]> Eric's Git Repo - ericdock.git/commitdiff
Added clock display
authorEricDWertz <EricDWertz@gmail.com>
Tue, 27 Sep 2016 13:41:30 +0000 (09:41 -0400)
committerEricDWertz <EricDWertz@gmail.com>
Tue, 27 Sep 2016 13:41:30 +0000 (09:41 -0400)
Makefile
clock.h [new file with mode: 0644]
dock_icon.h
main.c

index 742ca1ed85b652d90a74a6e90003374710e452f0..049e73e05c3ac5d58a803fd40e14b541fb607cc8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,2 @@
-ericwindow-test: main.c
-       gcc -o ericwindow-test -lX11 `pkg-config --cflags --libs gtk+-3.0 libwnck-3.0` main.c
+ericdock: main.c
+       gcc -o ericdock -lm -lX11 `pkg-config --cflags --libs gtk+-3.0 libwnck-3.0` main.c
diff --git a/clock.h b/clock.h
new file mode 100644 (file)
index 0000000..a82c2af
--- /dev/null
+++ b/clock.h
@@ -0,0 +1,152 @@
+#pragma once
+/*
+ * Clock drawing functions
+ */
+#include <gtk/gtk.h>
+
+#include <time.h>
+#include <math.h>
+#include <stdint.h>
+
+#include "eric_window.h"
+
+double clock_alpha=0.75;
+double clock_height = 18.0;
+
+int displaymode=0;
+
+char* weekday_names[7]=
+{
+       "Sunday",
+       "Monday",
+       "Tuesday",
+       "Wednesday",
+       "Thursday",
+       "Friday",
+       "Saturday"
+};
+
+char* month_names[12]=
+{
+       "January",
+       "February",
+       "March",
+       "April",
+       "May",
+       "June",
+       "July",
+       "August",
+       "September",
+       "October",
+       "November",
+       "December"
+};
+
+int oldsec;
+gboolean clock_refresh(gpointer data)
+{
+    time_t rawtime;
+    time ( &rawtime );
+    struct tm * timeinfo;
+
+    timeinfo = localtime ( &rawtime );
+    if( timeinfo->tm_sec != oldsec );
+        gtk_widget_queue_draw( GTK_WIDGET( data ) );
+
+    return TRUE;
+}
+
+void clock_init( gpointer window )
+{
+    g_timeout_add_seconds(1,clock_refresh, window);
+}
+
+void clock_draw_timestring(cairo_t* cr, double x, double y, int blurpass)
+{
+    time_t rawtime;
+    struct tm * timeinfo;
+
+    time ( &rawtime );
+    timeinfo = localtime ( &rawtime );
+    //tm_sec tm_min tm_hour
+    int hour=timeinfo->tm_hour;
+    int minute=timeinfo->tm_min;
+    int second=timeinfo->tm_sec;
+    //hour+=minute/60;
+    char ampm[3]="am";
+    if(hour>=12) 
+    {
+       hour-=12;
+       ampm[0]='p';
+    }
+    if(hour==0)
+    {
+       hour=12;
+    }
+    oldsec = timeinfo->tm_sec;
+    
+    if(blurpass==1) cairo_translate(cr,-2.0,0);
+    
+    cairo_text_extents_t extents;
+    double text_x = x;
+    char timestring[64];
+    cairo_set_font_face(cr,cairo_toy_font_face_create("Source Sans Pro",CAIRO_FONT_SLANT_NORMAL,CAIRO_FONT_WEIGHT_NORMAL));
+    
+    cairo_set_font_size(cr, SCALE_VALUE( clock_height ) );
+    sprintf(timestring,"%i:%02i%s",hour, minute, ampm);
+    cairo_text_extents(cr,timestring,&extents);
+    text_x-=extents.x_advance;
+    cairo_move_to(cr,text_x, y + extents.y_bearing + extents.height - SCALE_VALUE( 2.0 ) );
+    cairo_text_path(cr,timestring);
+
+    sprintf(timestring,"%02i/%02i/%02i", 
+            timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_year + 1900 );
+    cairo_text_extents(cr,timestring,&extents);
+    text_x = x - extents.x_advance;
+    cairo_move_to(cr,text_x, y - extents.y_bearing + SCALE_VALUE( 2.0 ) );
+    cairo_text_path(cr,timestring);
+
+    //sprintf(timestring,"%s, %s %i, %i",weekday_names[timeinfo->tm_wday],month_names[timeinfo->tm_mon],timeinfo->tm_mday,timeinfo->tm_year+1900);
+    //cairo_text_extents(cr,timestring,&extents);
+    //text_x= x - extents.x_advance;
+    //cairo_move_to(cr,text_x, y + SCALE_VALUE( 32.0 ) );
+    //cairo_text_path(cr,timestring);
+    
+    //cairo_set_font_size(cr,32.0);
+    //sprintf(timestring,"%i:%02i",hour,minute);
+    //cairo_text_extents(cr,timestring,&extents);
+    //text_x-=extents.x_advance;
+    //cairo_move_to(cr,text_x, y + 16.0 );
+    //cairo_text_path(cr,timestring);
+    
+    
+    
+    //cairo_set_font_size(cr,16.0);
+    
+    if(blurpass==1) 
+    {
+       cairo_set_line_width(cr,4.0);
+       cairo_stroke_preserve(cr);
+    }
+    cairo_fill(cr);
+}
+
+void clock_draw( cairo_t* cr, double x, double y, eric_window* w )
+{
+    //cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, clock_alpha);
+    //if(clock_alpha!=0) draw_clock(cr,2.0);  
+    
+    w->text_color.red = 1.0 - w->text_color.red;
+    w->text_color.green = 1.0 - w->text_color.green;
+    w->text_color.blue = 1.0 - w->text_color.blue;
+    w->text_color.alpha = 0.25 * clock_alpha;
+    gdk_cairo_set_source_rgba( cr, &w->text_color );
+    clock_draw_timestring( cr, x + SCALE_VALUE( 1.0 ), y + SCALE_VALUE( 1.0 ), 0 );
+
+    w->text_color.red = 1.0 - w->text_color.red;
+    w->text_color.green = 1.0 - w->text_color.green;
+    w->text_color.blue = 1.0 - w->text_color.blue;
+    w->text_color.alpha = clock_alpha;
+    gdk_cairo_set_source_rgba( cr, &w->text_color );
+    clock_draw_timestring( cr, x, y, 0 );
+}
index b1bf3edab94d7b34a0676c0ca4891b3918977d00..2f376f6a9b628ba6c9e7783de4d90f0126d93b9f 100644 (file)
@@ -34,8 +34,8 @@ dock_icon* dock_icon_create( WnckClassGroup* class_group )
     icon->pager_items = NULL;
     icon->icon_state = ICON_STATE_NORMAL;
 
-    icon->width = SCALE_VALUE( 42 );
-    icon->height = SCALE_VALUE( 48 );
+    icon->width = SCALE_VALUE( BAR_HEIGHT - 6.0 );
+    icon->height = SCALE_VALUE( BAR_HEIGHT );
 
     icon->selected_index = 0;
 
diff --git a/main.c b/main.c
index 6dba789988df3dc81adf3bb1864ef56d15809443..b8c1ee8a7a297e87ced4a004eaa8f0b216f6815d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -13,6 +13,7 @@
 #define ERIC_DOCK_TOOLTIP_ITEM_HEIGHT 24.0
 #define UI_SCALE 1.0
 #define SCALE_VALUE(x) (x)*UI_SCALE
+#define BAR_HEIGHT 48.0
 
 #define ICON_STATE_NORMAL 0
 #define ICON_STATE_HOVER 1
@@ -30,6 +31,8 @@ eric_window* dock_window = NULL;
 
 #include "tooltip_window.h"
 
+#include "clock.h"
+
 //Logic to add a window to the pager items.
 //If a matching class group already exists it will be added to that, otherwise create
 //a new class group and add the window to that.
@@ -182,6 +185,8 @@ static gboolean draw_dock_window( GtkWidget* widget, cairo_t* cr, eric_window* w
 
         x += SCALE_VALUE( 47.0 );
     }
+    clock_draw( cr, 1910, BAR_HEIGHT / 2.0, w );
+
     return FALSE;
 }
 
@@ -273,8 +278,8 @@ void setup_dock_window()
     sw = mon_geom.width;
     sh = mon_geom.height;
 
-    dock_window = eric_window_create( sw, 48 * UI_SCALE, "" );
-    gtk_window_move( GTK_WINDOW( dock_window->window ), 0, sh - 48 * UI_SCALE );
+    dock_window = eric_window_create( sw, BAR_HEIGHT * UI_SCALE, "" );
+    gtk_window_move( GTK_WINDOW( dock_window->window ), 0, sh - BAR_HEIGHT * UI_SCALE );
     gtk_window_set_type_hint( GTK_WINDOW( dock_window->window ), GDK_WINDOW_TYPE_HINT_DOCK );
 
     dock_window->draw_callback = draw_dock_window;
@@ -284,6 +289,9 @@ void setup_dock_window()
     g_signal_connect( G_OBJECT( dock_window->window ), "button-press-event", G_CALLBACK(dock_window_mouse_down), NULL );
 
     gtk_widget_show_now( dock_window->window );
+
+    //Init clock drawing
+    clock_init( dock_window->window );
 }
 
 static void wnck_window_opened( WnckScreen* screen, WnckWindow* window, gpointer data )