summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c62186d)
raw | patch | inline | side by side (parent: c62186d)
author | Eric Wertz <ericdwertz@gmail.com> | |
Sun, 4 Dec 2016 03:22:33 +0000 (22:22 -0500) | ||
committer | Eric Wertz <ericdwertz@gmail.com> | |
Sun, 4 Dec 2016 03:22:33 +0000 (22:22 -0500) |
12 files changed:
clock.c | [new file with mode: 0644] | patch | blob |
clock.h | patch | blob | history | |
dock_icon.c | [new file with mode: 0644] | patch | blob |
dock_icon.h | patch | blob | history | |
drawing.h | patch | blob | history | |
eric_window.c | [new file with mode: 0644] | patch | blob |
eric_window.h | patch | blob | history | |
ericdock.h | [new file with mode: 0644] | patch | blob |
main.c | patch | blob | history | |
pager_item.h | patch | blob | history | |
tooltip_window.c | [new file with mode: 0644] | patch | blob |
tooltip_window.h | patch | blob | history |
diff --git a/clock.c b/clock.c
--- /dev/null
+++ b/clock.c
@@ -0,0 +1,150 @@
+/*
+ * Clock drawing functions
+ */
+#include <time.h>
+#include <math.h>
+#include <stdint.h>
+
+#include "ericdock.h"
+#include "clock.h"
+
+double clock_alpha = 0.75;
+double clock_height = 0.18;
+
+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 - SCALE_VALUE( 4.0 ) );
+ cairo_text_path(cr,timestring);
+
+ sprintf(timestring,"%i/%02i/%02i",
+ timeinfo->tm_mon+1, 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( 4.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 0692d891aeb773ccb9308be44d511d5af663a595..3a2bd0d125ee61a98ac7e29d7dbe3243068291be 100644 (file)
--- a/clock.h
+++ b/clock.h
*/
#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 - SCALE_VALUE( 4.0 ) );
- cairo_text_path(cr,timestring);
-
- sprintf(timestring,"%i/%02i/%02i",
- timeinfo->tm_mon+1, 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( 4.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 );
+extern double clock_alpha;
+extern double clock_height;
+extern int displaymode;
+extern char* weekday_names[7];
+extern char* month_names[12];
- 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 );
-}
+gboolean clock_refresh(gpointer data);
+void clock_init( gpointer window );
+void clock_draw_timestring(cairo_t* cr, double x, double y, int blurpass);
+void clock_draw( cairo_t* cr, double x, double y, eric_window* w );
diff --git a/dock_icon.c b/dock_icon.c
--- /dev/null
+++ b/dock_icon.c
@@ -0,0 +1,113 @@
+/*
+ * dock_icon - Represents an icon on the dock
+ * holds pager_items
+ *
+ * renders/handles events based on how many pager_items it contains
+ */
+#include "dock_icon.h"
+#include "tooltip_window.h"
+
+eric_window* tooltip_window = NULL;
+dock_icon* tooltip_window_icon = NULL;
+
+dock_icon* dock_icon_create( WnckClassGroup* class_group )
+{
+ dock_icon* icon = malloc( sizeof( dock_icon ) );
+ icon->class_group = class_group;
+ icon->icon_pixbuf = wnck_class_group_get_icon( class_group );
+ icon->pager_items = NULL;
+ icon->icon_state = ICON_STATE_NORMAL;
+
+ icon->width = SCALE_VALUE( BAR_HEIGHT - 6.0 );
+ icon->height = SCALE_VALUE( BAR_HEIGHT );
+
+ icon->selected_index = 0;
+
+ return icon;
+}
+
+//Goes to the next pager item, looping back to the start if necessary
+pager_item* dock_icon_get_next_pager_item( dock_icon* icon )
+{
+ pager_item* item;
+
+ icon->selected_index++;
+ if( icon->selected_index >= g_list_length( icon->pager_items ) )
+ {
+ icon->selected_index = 0;
+ }
+
+ item = g_list_nth_data( icon->pager_items, icon->selected_index );
+
+ return item;
+}
+
+void dock_icon_clear_pager_item_state( dock_icon* icon )
+{
+ GList* pager_list;
+ pager_item* item;
+
+ for( pager_list = icon->pager_items; pager_list != NULL; pager_list = pager_list->next )
+ {
+ item = pager_list->data;
+ item->icon_state = ICON_STATE_NORMAL;
+ }
+}
+
+/* Event whenever a dock icon is clicked or selected via keyboard
+ * Will switch to app, or if more than one pager_items, show menu
+ */
+void dock_icon_activate( dock_icon* icon, Time time, int from_click )
+{
+ if( !icon->pager_items )
+ return;
+
+ if( g_list_length( icon->pager_items ) > 1 )
+ {
+ pager_item* item;
+
+ dock_icon_clear_pager_item_state( icon );
+
+ if( tooltip_window_icon != icon )
+ {
+ tooltip_window_icon = icon;
+ tooltip_window_show();
+ icon->selected_index = 0;
+ item = (pager_item*)icon->pager_items->data;
+ }
+ else
+ {
+ item = dock_icon_get_next_pager_item( icon );
+ }
+
+ if( !from_click )
+ {
+ item->icon_state = ICON_STATE_HOVER;
+ wnck_window_activate( item->window, time );
+ gtk_widget_queue_draw( tooltip_window->window );
+ }
+ }
+ else
+ {
+ //Activiate the only one we have
+ pager_item* item = (pager_item*)icon->pager_items->data;
+ wnck_window_activate( item->window, time );
+ tooltip_window_hide();
+ }
+
+ if( icon->icon_state == ICON_STATE_ALERT )
+ icon->icon_state = ICON_STATE_NORMAL;
+}
+
+void dock_icon_mouse_down( dock_icon* icon, double mx, double my, Time time )
+{
+ double it, ib, il, ir;
+
+ il = icon->x; ir = icon->x + icon->width;
+ it = icon->y; ib = icon->y + icon->height;
+
+ if( il < mx && mx < ir && it < my && my < ib )
+ {
+ dock_icon_activate( icon, time, TRUE );
+ }
+}
diff --git a/dock_icon.h b/dock_icon.h
index 16a18df7f7daf445f29fdf02690e5d3054f2a47b..a97c4b4ccf8cec11c0efe7cec48dda5dfb10d776 100644 (file)
--- a/dock_icon.h
+++ b/dock_icon.h
* renders/handles events based on how many pager_items it contains
*/
#include <gtk/gtk.h>
+#include <X11/Xlib.h>
#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <libwnck/libwnck.h>
+#include <time.h>
+
+#include "ericdock.h"
+#include "pager_item.h"
+
typedef struct
{
WnckClassGroup* class_group;
int selected_index;
} dock_icon;
-#include "tooltip_window.h"
-
-extern dock_icon* tooltip_window_icon;
-
-dock_icon* dock_icon_create( WnckClassGroup* class_group )
-{
- dock_icon* icon = malloc( sizeof( dock_icon ) );
- icon->class_group = class_group;
- icon->icon_pixbuf = wnck_class_group_get_icon( class_group );
- icon->pager_items = NULL;
- icon->icon_state = ICON_STATE_NORMAL;
-
- icon->width = SCALE_VALUE( BAR_HEIGHT - 6.0 );
- icon->height = SCALE_VALUE( BAR_HEIGHT );
-
- icon->selected_index = 0;
-
- return icon;
-}
-
-//Goes to the next pager item, looping back to the start if necessary
-pager_item* dock_icon_get_next_pager_item( dock_icon* icon )
-{
- pager_item* item;
-
- icon->selected_index++;
- if( icon->selected_index >= g_list_length( icon->pager_items ) )
- {
- icon->selected_index = 0;
- }
-
- item = g_list_nth_data( icon->pager_items, icon->selected_index );
-
- return item;
-}
-
-void dock_icon_clear_pager_item_state( dock_icon* icon )
-{
- GList* pager_list;
- pager_item* item;
-
- for( pager_list = icon->pager_items; pager_list != NULL; pager_list = pager_list->next )
- {
- item = pager_list->data;
- item->icon_state = ICON_STATE_NORMAL;
- }
-}
-
-/* Event whenever a dock icon is clicked or selected via keyboard
- * Will switch to app, or if more than one pager_items, show menu
- */
-void dock_icon_activate( dock_icon* icon, Time time, int from_click )
-{
- if( !icon->pager_items )
- return;
-
- if( g_list_length( icon->pager_items ) > 1 )
- {
- pager_item* item;
-
- dock_icon_clear_pager_item_state( icon );
-
- if( tooltip_window_icon != icon )
- {
- tooltip_window_icon = icon;
- tooltip_window_show();
- icon->selected_index = 0;
- item = (pager_item*)icon->pager_items->data;
- }
- else
- {
- item = dock_icon_get_next_pager_item( icon );
- }
-
- if( !from_click )
- {
- item->icon_state = ICON_STATE_HOVER;
- wnck_window_activate( item->window, time );
- gtk_widget_queue_draw( tooltip_window->window );
- }
- }
- else
- {
- //Activiate the only one we have
- pager_item* item = (pager_item*)icon->pager_items->data;
- wnck_window_activate( item->window, time );
- tooltip_window_hide();
- }
-
- if( icon->icon_state == ICON_STATE_ALERT )
- icon->icon_state = ICON_STATE_NORMAL;
-}
-
-void dock_icon_mouse_down( dock_icon* icon, double mx, double my, Time time )
-{
- double it, ib, il, ir;
-
- il = icon->x; ir = icon->x + icon->width;
- it = icon->y; ib = icon->y + icon->height;
-
- if( il < mx && mx < ir && it < my && my < ib )
- {
- dock_icon_activate( icon, time, TRUE );
- }
-}
+dock_icon* dock_icon_create( WnckClassGroup* class_group );
+pager_item* dock_icon_get_next_pager_item( dock_icon* icon );
+void dock_icon_clear_pager_item_state( dock_icon* icon );
+void dock_icon_activate( dock_icon* icon, Time time, int from_click );
+void dock_icon_mouse_down( dock_icon* icon, double mx, double my, Time time );
diff --git a/drawing.h b/drawing.h
index 9d9394cb4c4effacdf62bcae1fe5f67489a8ab98..ced8af9929700a773c9f3e3f0370322050bb94cb 100644 (file)
--- a/drawing.h
+++ b/drawing.h
* Drawing functions!
*/
#include <gtk/gtk.h>
+#include <math.h>
void draw_rounded_rect(cairo_t* cr,double x,double y,double w,double h,double r)
{
diff --git a/eric_window.c b/eric_window.c
--- /dev/null
+++ b/eric_window.c
@@ -0,0 +1,119 @@
+#include "eric_window.h"
+
+double gdk_rgba_get_luminance( GdkRGBA *color )
+{
+ return ( color->red ) * 0.2126 +
+ ( color->green ) * 0.7152 +
+ ( color->blue ) * 0.0722;
+}
+
+void gdk_color_lerp( GdkRGBA* c1, GdkRGBA* c2, double s, GdkRGBA* out )
+{
+ out->red = c1->red + ( c2->red - c1->red ) * s;
+ out->green = c1->green + ( c2->green - c1->green ) * s;
+ out->blue = c1->blue + ( c2->blue - c1->blue ) * s;
+ out->alpha = c1->alpha + ( c2->alpha - c1->alpha ) * s;
+}
+
+gboolean eric_window_animation_timer( eric_window* w )
+{
+ w->background_change_percentage += 0.05;
+ gdk_color_lerp( &w->background_color_old, &w->background_color_new,
+ w->background_change_percentage, &w->background_color);
+ gdk_color_lerp( &w->text_color_old, &w->text_color_new,
+ w->background_change_percentage, &w->text_color);
+ gtk_widget_queue_draw( w->window );
+
+ if( w->background_change_percentage >= 1.0 ) return FALSE;
+
+ return TRUE;
+}
+
+gboolean eric_window_draw( GtkWidget* widget, cairo_t* cr, eric_window* w )
+{
+ cairo_set_operator(cr,CAIRO_OPERATOR_SOURCE);
+ w->background_color.alpha = 0.75;
+ gdk_cairo_set_source_rgba( cr, &w->background_color );
+ cairo_paint( cr );
+
+ if( w->draw_callback == NULL )
+ return FALSE;
+ else
+ return w->draw_callback( widget, cr, w );
+}
+
+
+void eric_window_screen_changed( GtkWidget *widget, GdkScreen *old_screen, gpointer userdata )
+{
+ GdkVisual *visual;
+
+ GdkScreen* screen=gtk_widget_get_screen(widget);
+ if(!screen) return;
+
+ visual = gdk_screen_get_rgba_visual(screen);
+ if(visual==NULL) visual=gdk_screen_get_system_visual(screen);
+
+ gtk_widget_set_visual(widget,visual);
+}
+
+void eric_window_gsettings_value_changed( GSettings *settings, const gchar *key, eric_window* w )
+{
+ if( strcmp( key, "primary-color" ) == 0 )
+ {
+ w->background_color_old = w->background_color;
+ gdk_rgba_parse( &w->background_color_new, g_settings_get_string( settings, "primary-color" ) );
+ w->text_color_old = w->text_color;
+ if( gdk_rgba_get_luminance( &w->background_color_new ) > 0.5 )
+ gdk_rgba_parse( &w->text_color_new, "#000000" );
+ else
+ gdk_rgba_parse( &w->text_color_new, "#FFFFFF" );
+
+ w->background_change_percentage = 0.0;
+ g_timeout_add( 32, (gpointer)eric_window_animation_timer, w );
+ }
+}
+
+eric_window* eric_window_create( int width, int height, char* title )
+{
+ eric_window* w = malloc( sizeof( eric_window ) );
+ w->draw_callback = NULL;
+
+ if( title == NULL )
+ title = "eric window";
+
+ w->window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
+ gtk_window_set_title( GTK_WINDOW( w->window ), title );
+ gtk_window_resize( GTK_WINDOW( w->window ), width, height );
+ gtk_widget_add_events( w->window, GDK_STRUCTURE_MASK );
+
+ gtk_widget_set_app_paintable( w->window, TRUE );
+
+ g_signal_connect( G_OBJECT( w->window ), "draw", G_CALLBACK(eric_window_draw), (gpointer)w );
+ g_signal_connect( G_OBJECT( w->window ), "screen-changed", G_CALLBACK(eric_window_screen_changed), (gpointer)w );
+ g_signal_connect( G_OBJECT( w->window ), "delete-event", gtk_main_quit, NULL );
+
+ eric_window_screen_changed( w->window, NULL, NULL );
+
+ /* GSettings Stuff */
+ GSettings* gsettings;
+ GSettingsSchema* gsettings_schema;
+
+ gsettings_schema = g_settings_schema_source_lookup( g_settings_schema_source_get_default(),
+ "org.gnome.desktop.background",
+ TRUE );
+ if( gsettings_schema )
+ {
+ g_settings_schema_unref (gsettings_schema);
+ gsettings_schema = NULL;
+ gsettings = g_settings_new ( "org.gnome.desktop.background" );
+ }
+
+ g_signal_connect_data( gsettings, "changed", G_CALLBACK( eric_window_gsettings_value_changed ), (gpointer)w, 0, 0 );
+ gdk_rgba_parse( &w->background_color, g_settings_get_string( gsettings, "primary-color" ) );
+ if( gdk_rgba_get_luminance( &w->background_color ) > 0.5 )
+ gdk_rgba_parse( &w->text_color, "#000000" );
+ else
+ gdk_rgba_parse( &w->text_color, "#FFFFFF" );
+
+ return w;
+}
diff --git a/eric_window.h b/eric_window.h
index 155b76eff692155420981c25dc5b768a794bc8d1..8cb667abab7b051d69b74e534f4f352a2d9ad443 100644 (file)
--- a/eric_window.h
+++ b/eric_window.h
gboolean (*draw_callback)( GtkWidget* widget, cairo_t* cr, eric_window* w );
};
-double gdk_rgba_get_luminance( GdkRGBA *color )
-{
- return ( color->red ) * 0.2126 +
- ( color->green ) * 0.7152 +
- ( color->blue ) * 0.0722;
-}
-
-static void gdk_color_lerp( GdkRGBA* c1, GdkRGBA* c2, double s, GdkRGBA* out )
-{
- out->red = c1->red + ( c2->red - c1->red ) * s;
- out->green = c1->green + ( c2->green - c1->green ) * s;
- out->blue = c1->blue + ( c2->blue - c1->blue ) * s;
- out->alpha = c1->alpha + ( c2->alpha - c1->alpha ) * s;
-}
-
-static gboolean eric_window_animation_timer( eric_window* w )
-{
- w->background_change_percentage += 0.05;
- gdk_color_lerp( &w->background_color_old, &w->background_color_new,
- w->background_change_percentage, &w->background_color);
- gdk_color_lerp( &w->text_color_old, &w->text_color_new,
- w->background_change_percentage, &w->text_color);
- gtk_widget_queue_draw( w->window );
-
- if( w->background_change_percentage >= 1.0 ) return FALSE;
-
- return TRUE;
-}
-
-static gboolean eric_window_draw( GtkWidget* widget, cairo_t* cr, eric_window* w )
-{
- cairo_set_operator(cr,CAIRO_OPERATOR_SOURCE);
- w->background_color.alpha = 0.75;
- gdk_cairo_set_source_rgba( cr, &w->background_color );
- cairo_paint( cr );
-
- if( w->draw_callback == NULL )
- return FALSE;
- else
- return w->draw_callback( widget, cr, w );
-}
-
-
-static void eric_window_screen_changed( GtkWidget *widget, GdkScreen *old_screen, gpointer userdata )
-{
- GdkVisual *visual;
-
- GdkScreen* screen=gtk_widget_get_screen(widget);
- if(!screen) return;
-
- visual = gdk_screen_get_rgba_visual(screen);
- if(visual==NULL) visual=gdk_screen_get_system_visual(screen);
-
- gtk_widget_set_visual(widget,visual);
-}
-
-void eric_window_gsettings_value_changed( GSettings *settings, const gchar *key, eric_window* w )
-{
- if( strcmp( key, "primary-color" ) == 0 )
- {
- w->background_color_old = w->background_color;
- gdk_rgba_parse( &w->background_color_new, g_settings_get_string( settings, "primary-color" ) );
- w->text_color_old = w->text_color;
- if( gdk_rgba_get_luminance( &w->background_color_new ) > 0.5 )
- gdk_rgba_parse( &w->text_color_new, "#000000" );
- else
- gdk_rgba_parse( &w->text_color_new, "#FFFFFF" );
-
- w->background_change_percentage = 0.0;
- g_timeout_add( 32, (gpointer)eric_window_animation_timer, w );
- }
-}
-
-eric_window* eric_window_create( int width, int height, char* title )
-{
- eric_window* w = malloc( sizeof( eric_window ) );
- w->draw_callback = NULL;
-
- if( title == NULL )
- title = "eric window";
-
- w->window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
- gtk_window_set_title( GTK_WINDOW( w->window ), title );
- gtk_window_resize( GTK_WINDOW( w->window ), width, height );
- gtk_widget_add_events( w->window, GDK_STRUCTURE_MASK );
-
- gtk_widget_set_app_paintable( w->window, TRUE );
-
- g_signal_connect( G_OBJECT( w->window ), "draw", G_CALLBACK(eric_window_draw), (gpointer)w );
- g_signal_connect( G_OBJECT( w->window ), "screen-changed", G_CALLBACK(eric_window_screen_changed), (gpointer)w );
- g_signal_connect( G_OBJECT( w->window ), "delete-event", gtk_main_quit, NULL );
-
- eric_window_screen_changed( w->window, NULL, NULL );
-
- /* GSettings Stuff */
- GSettings* gsettings;
- GSettingsSchema* gsettings_schema;
-
- gsettings_schema = g_settings_schema_source_lookup( g_settings_schema_source_get_default(),
- "org.gnome.desktop.background",
- TRUE );
- if( gsettings_schema )
- {
- g_settings_schema_unref (gsettings_schema);
- gsettings_schema = NULL;
- gsettings = g_settings_new ( "org.gnome.desktop.background" );
- }
-
- g_signal_connect_data( gsettings, "changed", G_CALLBACK( eric_window_gsettings_value_changed ), (gpointer)w, 0, 0 );
- gdk_rgba_parse( &w->background_color, g_settings_get_string( gsettings, "primary-color" ) );
- if( gdk_rgba_get_luminance( &w->background_color ) > 0.5 )
- gdk_rgba_parse( &w->text_color, "#000000" );
- else
- gdk_rgba_parse( &w->text_color, "#FFFFFF" );
-
- return w;
-}
+double gdk_rgba_get_luminance( GdkRGBA *color );
+void gdk_color_lerp( GdkRGBA* c1, GdkRGBA* c2, double s, GdkRGBA* out );
+gboolean eric_window_animation_timer( eric_window* w );
+gboolean eric_window_draw( GtkWidget* widget, cairo_t* cr, eric_window* w );
+void eric_window_screen_changed( GtkWidget *widget, GdkScreen *old_screen, gpointer userdata );
+void eric_window_gsettings_value_changed( GSettings *settings, const gchar *key, eric_window* w );
+eric_window* eric_window_create( int width, int height, char* title );
diff --git a/ericdock.h b/ericdock.h
--- /dev/null
+++ b/ericdock.h
@@ -0,0 +1,22 @@
+#pragma once
+/*
+ * Global header for ericdock stuff
+ */
+
+#include "eric_window.h"
+
+#define ERIC_DOCK_FONT "Source Sans Pro Regular"
+#define ERIC_DOCK_TOOLTIP_SHADOW_RADIUS 16.0
+#define ERIC_DOCK_TOOLTIP_WIDTH ERIC_DOCK_TOOLTIP_SHADOW_RADIUS + 320.0
+#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
+#define ICON_STATE_ACTIVE 2
+#define ICON_STATE_ALERT 3
+
+extern GList* dock_icons;
+extern eric_window* dock_window;
index c55b76535103c7216ef0544148834a4a1c11c004..a02c03d6b8d84214d9af4840d1349416b449765e 100644 (file)
--- a/main.c
+++ b/main.c
#include "eric_window.h"
-#define ERIC_DOCK_FONT "Source Sans Pro Regular"
-#define ERIC_DOCK_TOOLTIP_SHADOW_RADIUS 16.0
-#define ERIC_DOCK_TOOLTIP_WIDTH ERIC_DOCK_TOOLTIP_SHADOW_RADIUS + 320.0
-#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
-#define ICON_STATE_ACTIVE 2
-#define ICON_STATE_ALERT 3
-
GList* dock_icons = NULL;
eric_window* dock_window = NULL;
+#include "ericdock.h"
+#include "clock.h"
+
//Structure to hold actual pager items
#include "pager_item.h"
#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
@@ -98,12 +87,21 @@ GdkFilterReturn handle_x11_event( GdkXEvent *xevent, GdkEvent *event, gpointer d
}
else
{
- printf( "Got a number key press event!\n" );
+ if( xev->xkey.keycode >= 10 && xev->xkey.keycode <= 20 )
+ {
+ printf( "Got a number key press event!\n" );
+
+ icon = get_dock_icon_at_position( xev->xkey.keycode - 10 );
+ if( icon )
+ {
+ dock_icon_activate( icon, xev->xkey.time, FALSE );
+ }
+ }
- icon = get_dock_icon_at_position( xev->xkey.keycode - 10 );
- if( icon )
+ //L key press to lock the screen TODO: adjust this command
+ if( xev->xkey.keycode == 46 )
{
- dock_icon_activate( icon, xev->xkey.time, FALSE );
+ system( "/home/eric/EricOS/ericlock/ericlock" );
}
}
}
diff --git a/pager_item.h b/pager_item.h
index eb56e78c0cf97f72fa1f9605d7b1a2bcfb407cbc..ebee6ade82173846bbbeb7e97a837837d883e572 100644 (file)
--- a/pager_item.h
+++ b/pager_item.h
* pager_item - held by the dock_icon object
*/
+#include <string.h>
+#include <stdlib.h>
#include <gtk/gtk.h>
#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <libwnck/libwnck.h>
#include "drawing.h"
+#include "eric_window.h"
//Structure to hold actual pager items
typedef struct
int pager_item_mouse_move( pager_item* item, double mx, double my )
{
double it, ib, il, ir;
- int old_state, state_changed;
+ int old_state;
old_state = item->icon_state;
diff --git a/tooltip_window.c b/tooltip_window.c
--- /dev/null
+++ b/tooltip_window.c
@@ -0,0 +1,150 @@
+#include "tooltip_window.h"
+#include "ericdock.h"
+
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+
+#include "dock_icon.h"
+#include "drawing.h"
+
+eric_window* tooltip_window = NULL;
+dock_icon* tooltip_window_icon = NULL;
+
+void tooltip_window_hide()
+{
+ tooltip_window_icon = NULL;
+ gtk_widget_hide( tooltip_window->window );
+}
+
+gboolean tooltip_window_lose_focus( GtkWidget* widget, GdkEvent* event, gpointer user )
+{
+ tooltip_window_hide();
+ return TRUE;
+}
+
+void tooltip_window_mouse_down( GtkWidget* widget, GdkEvent* event, gpointer user )
+{
+ GdkEventButton* e = (GdkEventButton*)event;
+ if( e->button != 1 )
+ return;
+
+ double mx, my;
+ double it, ib, il, ir;
+ dock_icon* icon;
+ pager_item* item;
+ GList* pager_list;
+
+ mx = e->x; my = e->y;
+ for( pager_list = tooltip_window_icon->pager_items; pager_list != NULL; pager_list = pager_list->next )
+ {
+ item = pager_list->data;
+ if( my > item->y && my < item->y + SCALE_VALUE( 24.0 ) )
+ {
+ wnck_window_activate( item->window, e->time );
+ tooltip_window_hide();
+ }
+ }
+}
+
+gboolean tooltip_window_mouse_move( GtkWidget* widget, GdkEvent* event, gpointer user )
+{
+ double mx, my;
+ double it, ib, il, ir;
+ int old_state, new_state, state_changed;
+ dock_icon* icon;
+ pager_item* item;
+ GList *icon_list, *item_list;
+ GdkEventMotion* e = (GdkEventMotion*)event;
+
+ mx = e->x;
+ my = e->y;
+
+ for( item_list = tooltip_window_icon->pager_items; item_list != NULL; item_list = item_list->next )
+ {
+ item = item_list->data;
+
+
+ if( pager_item_mouse_move( item, mx, my ) )
+ state_changed = TRUE;
+ }
+
+ if( state_changed )
+ gtk_widget_queue_draw( tooltip_window->window );
+
+ return FALSE;
+}
+
+gboolean tooltip_window_draw( GtkWidget* widget, cairo_t* cr, eric_window* w )
+{
+ double x, y;
+ GList* pager_list;
+ pager_item* item;
+ cairo_pattern_t* pattern;
+
+ cairo_set_operator( cr, CAIRO_OPERATOR_OVER );
+ w->text_color.alpha = 1.0;
+ cairo_set_font_face( cr, cairo_toy_font_face_create( ERIC_DOCK_FONT, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL ) );
+ cairo_set_font_size( cr, SCALE_VALUE( 12.0 ) );
+
+ x = SCALE_VALUE( 5.0 ); //margin-left
+ y = SCALE_VALUE( 2.0 ); //margin-top
+ pattern = cairo_pattern_create_linear( SCALE_VALUE( ERIC_DOCK_TOOLTIP_WIDTH - 21.0 ), 0, SCALE_VALUE( ERIC_DOCK_TOOLTIP_WIDTH - 5.0 ), 0 );
+ cairo_pattern_add_color_stop_rgba( pattern, 0.0, w->text_color.red, w->text_color.green, w->text_color.blue, 1.0 );
+ cairo_pattern_add_color_stop_rgba( pattern, 1.0, w->text_color.red, w->text_color.green, w->text_color.blue, 0.0 );
+ for( pager_list = tooltip_window_icon->pager_items; pager_list != NULL; pager_list = pager_list->next )
+ {
+ item = (pager_item*)pager_list->data;
+
+ item->x = x;
+ item->y = y;
+ pager_item_draw( item, cr, w, pattern );
+
+ y += SCALE_VALUE( 24.0 );
+ }
+
+ cairo_pattern_destroy( pattern );
+}
+
+
+
+void tooltip_window_create( GtkWidget* dock_window )
+{
+ eric_window* w = eric_window_create( 10, 10, "" );
+ gtk_window_move( GTK_WINDOW( w->window ), 0, 1040 );
+ gtk_window_set_type_hint( GTK_WINDOW( w->window ), GDK_WINDOW_TYPE_HINT_DIALOG );
+ gtk_window_set_decorated( GTK_WINDOW( w->window ), FALSE );
+ gtk_window_set_skip_pager_hint( GTK_WINDOW( w->window ), TRUE );
+ gtk_window_set_transient_for( GTK_WINDOW( w->window ), GTK_WINDOW( dock_window ) );
+ gtk_window_set_keep_above( GTK_WINDOW( w->window ), TRUE );
+
+ gtk_widget_add_events( w->window, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK );
+ g_signal_connect( G_OBJECT( w->window ), "focus-out-event", G_CALLBACK(tooltip_window_lose_focus), NULL );
+ g_signal_connect( G_OBJECT( w->window ), "motion-notify-event", G_CALLBACK(tooltip_window_mouse_move), NULL );
+ g_signal_connect( G_OBJECT( w->window ), "button-press-event", G_CALLBACK(tooltip_window_mouse_down), NULL );
+ w->draw_callback = tooltip_window_draw;
+
+ tooltip_window = w;
+}
+
+
+void tooltip_window_update_geometry()
+{
+ int pager_count;
+ int wx, wy;
+
+ pager_count = g_list_length( tooltip_window_icon->pager_items );
+
+ gtk_window_get_position( GTK_WINDOW( dock_window->window ), &wx, &wy );
+ gtk_window_resize( GTK_WINDOW( tooltip_window->window ), SCALE_VALUE(ERIC_DOCK_TOOLTIP_WIDTH), SCALE_VALUE( pager_count * 24 ) );
+ gtk_window_move( GTK_WINDOW( tooltip_window->window ), wx + (int)tooltip_window_icon->x, wy - (int)SCALE_VALUE( pager_count * 24 ) );
+}
+
+void tooltip_window_show()
+{
+ int wx, wy;
+ int w, h;
+
+ tooltip_window_update_geometry();
+ gtk_widget_show_all( tooltip_window->window );
+ gtk_widget_queue_draw( tooltip_window->window );
+}
diff --git a/tooltip_window.h b/tooltip_window.h
index ca0c61813a0c4e468302a6d08956d0345f49727f..b4bd52fdb304d58ba4f68c4c2cf09bf66d87c5be 100644 (file)
--- a/tooltip_window.h
+++ b/tooltip_window.h
#pragma once
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
-
+#include <gtk/gtk.h>
#include "eric_window.h"
#include "dock_icon.h"
-#include "drawing.h"
-
-eric_window* tooltip_window = NULL;
-dock_icon* tooltip_window_icon = NULL;
-
-void tooltip_window_hide()
-{
- tooltip_window_icon = NULL;
- gtk_widget_hide( tooltip_window->window );
-}
-
-gboolean tooltip_window_lose_focus( GtkWidget* widget, GdkEvent* event, gpointer user )
-{
- tooltip_window_hide();
- return TRUE;
-}
-
-void tooltip_window_mouse_down( GtkWidget* widget, GdkEvent* event, gpointer user )
-{
- GdkEventButton* e = (GdkEventButton*)event;
- if( e->button != 1 )
- return;
-
- double mx, my;
- double it, ib, il, ir;
- dock_icon* icon;
- pager_item* item;
- GList* pager_list;
-
- mx = e->x; my = e->y;
- for( pager_list = tooltip_window_icon->pager_items; pager_list != NULL; pager_list = pager_list->next )
- {
- item = pager_list->data;
- if( my > item->y && my < item->y + SCALE_VALUE( 24.0 ) )
- {
- wnck_window_activate( item->window, e->time );
- tooltip_window_hide();
- }
- }
-}
-
-gboolean tooltip_window_mouse_move( GtkWidget* widget, GdkEvent* event, gpointer user )
-{
- double mx, my;
- double it, ib, il, ir;
- int old_state, new_state, state_changed;
- dock_icon* icon;
- pager_item* item;
- GList *icon_list, *item_list;
- GdkEventMotion* e = (GdkEventMotion*)event;
-
- mx = e->x;
- my = e->y;
-
- for( item_list = tooltip_window_icon->pager_items; item_list != NULL; item_list = item_list->next )
- {
- item = item_list->data;
-
-
- if( pager_item_mouse_move( item, mx, my ) )
- state_changed = TRUE;
- }
-
- if( state_changed )
- gtk_widget_queue_draw( tooltip_window->window );
-
- return FALSE;
-}
-
-static gboolean tooltip_window_draw( GtkWidget* widget, cairo_t* cr, eric_window* w )
-{
- double x, y;
- GList* pager_list;
- pager_item* item;
- cairo_pattern_t* pattern;
-
- cairo_set_operator( cr, CAIRO_OPERATOR_OVER );
- w->text_color.alpha = 1.0;
- cairo_set_font_face( cr, cairo_toy_font_face_create( ERIC_DOCK_FONT, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL ) );
- cairo_set_font_size( cr, SCALE_VALUE( 12.0 ) );
-
- x = SCALE_VALUE( 5.0 ); //margin-left
- y = SCALE_VALUE( 2.0 ); //margin-top
- pattern = cairo_pattern_create_linear( SCALE_VALUE( ERIC_DOCK_TOOLTIP_WIDTH - 21.0 ), 0, SCALE_VALUE( ERIC_DOCK_TOOLTIP_WIDTH - 5.0 ), 0 );
- cairo_pattern_add_color_stop_rgba( pattern, 0.0, w->text_color.red, w->text_color.green, w->text_color.blue, 1.0 );
- cairo_pattern_add_color_stop_rgba( pattern, 1.0, w->text_color.red, w->text_color.green, w->text_color.blue, 0.0 );
- for( pager_list = tooltip_window_icon->pager_items; pager_list != NULL; pager_list = pager_list->next )
- {
- item = (pager_item*)pager_list->data;
-
- item->x = x;
- item->y = y;
- pager_item_draw( item, cr, w, pattern );
-
- y += SCALE_VALUE( 24.0 );
- }
-
- cairo_pattern_destroy( pattern );
-}
-
-
-
-void tooltip_window_create( GtkWidget* dock_window )
-{
- eric_window* w = eric_window_create( 10, 10, "" );
- gtk_window_move( GTK_WINDOW( w->window ), 0, 1040 );
- gtk_window_set_type_hint( GTK_WINDOW( w->window ), GDK_WINDOW_TYPE_HINT_DIALOG );
- gtk_window_set_decorated( GTK_WINDOW( w->window ), FALSE );
- gtk_window_set_skip_pager_hint( GTK_WINDOW( w->window ), TRUE );
- gtk_window_set_transient_for( GTK_WINDOW( w->window ), GTK_WINDOW( dock_window ) );
- gtk_window_set_keep_above( GTK_WINDOW( w->window ), TRUE );
-
- gtk_widget_add_events( w->window, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK );
- g_signal_connect( G_OBJECT( w->window ), "focus-out-event", G_CALLBACK(tooltip_window_lose_focus), NULL );
- g_signal_connect( G_OBJECT( w->window ), "motion-notify-event", G_CALLBACK(tooltip_window_mouse_move), NULL );
- g_signal_connect( G_OBJECT( w->window ), "button-press-event", G_CALLBACK(tooltip_window_mouse_down), NULL );
- w->draw_callback = tooltip_window_draw;
-
- tooltip_window = w;
-}
-
-
-void tooltip_window_update_geometry()
-{
- int pager_count;
- int wx, wy;
-
- pager_count = g_list_length( tooltip_window_icon->pager_items );
-
- gtk_window_get_position( GTK_WINDOW( dock_window->window ), &wx, &wy );
- gtk_window_resize( GTK_WINDOW( tooltip_window->window ), SCALE_VALUE(ERIC_DOCK_TOOLTIP_WIDTH), SCALE_VALUE( pager_count * 24 ) );
- gtk_window_move( GTK_WINDOW( tooltip_window->window ), wx + (int)tooltip_window_icon->x, wy - (int)SCALE_VALUE( pager_count * 24 ) );
-}
-
-void tooltip_window_show()
-{
- int wx, wy;
- int w, h;
-
- tooltip_window_update_geometry();
- gtk_widget_show_all( tooltip_window->window );
- gtk_widget_queue_draw( tooltip_window->window );
-}
+extern eric_window* tooltip_window;
+extern dock_icon* tooltip_window_icon;
+
+void tooltip_window_hide();
+gboolean tooltip_window_lose_focus( GtkWidget* widget, GdkEvent* event, gpointer user );
+void tooltip_window_mouse_down( GtkWidget* widget, GdkEvent* event, gpointer user );
+gboolean tooltip_window_mouse_move( GtkWidget* widget, GdkEvent* event, gpointer user );
+gboolean tooltip_window_draw( GtkWidget* widget, cairo_t* cr, eric_window* w );
+void tooltip_window_create( GtkWidget* dock_window );
+void tooltip_window_update_geometry();
+void tooltip_window_show();