|
|
@ -20,6 +20,7 @@ |
|
|
|
#endif |
|
|
|
|
|
|
|
#include <gdk/gdk.h> |
|
|
|
#include <panel/panel-private.c> |
|
|
|
#include <libxfce4util/libxfce4util.h> |
|
|
|
#include <libxfce4panel/libxfce4panel.h> |
|
|
|
#include <libxfce4panel/xfce-panel-plugin-provider.h> |
|
|
@ -43,52 +44,80 @@ struct _WrapperPlugClass |
|
|
|
struct _WrapperPlug |
|
|
|
{ |
|
|
|
GtkPlug __parent__; |
|
|
|
|
|
|
|
|
|
|
|
/* the panel plugin */ |
|
|
|
XfcePanelPluginProvider *provider; |
|
|
|
|
|
|
|
|
|
|
|
/* socket id of panel window */ |
|
|
|
GdkNativeWindow socket_id; |
|
|
|
|
|
|
|
|
|
|
|
/* the message atom */ |
|
|
|
GdkAtom atom; |
|
|
|
|
|
|
|
/* background alpha */ |
|
|
|
gdouble background_alpha; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (WrapperPlug, wrapper_plug, GTK_TYPE_PLUG); |
|
|
|
|
|
|
|
//~ static gboolean
|
|
|
|
//~ wrapper_plug_expose_event (GtkWidget *widget,
|
|
|
|
//~ GdkEventExpose *event)
|
|
|
|
//~ {
|
|
|
|
//~ cairo_t *cr;
|
|
|
|
//~ GtkStyle *style;
|
|
|
|
//~ double r,g,b;
|
|
|
|
//~
|
|
|
|
//~ cr = gdk_cairo_create (widget->window);
|
|
|
|
//~
|
|
|
|
//~ cairo_rectangle (cr, event->area.x,
|
|
|
|
//~ event->area.y,
|
|
|
|
//~ event->area.width,
|
|
|
|
//~ event->area.height);
|
|
|
|
//~ cairo_clip (cr);
|
|
|
|
//~
|
|
|
|
//~ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
//~
|
|
|
|
//~ /* fully transparent */
|
|
|
|
//~ style = gtk_widget_get_style (widget);
|
|
|
|
//~ r = (double) style->bg[widget->state].red / (double) 65535;
|
|
|
|
//~ g = (double) style->bg[widget->state].green / (double) 65535;
|
|
|
|
//~ b = (double) style->bg[widget->state].blue / (double) 65535;
|
|
|
|
//~ cairo_set_source_rgba (cr, r, g, b, 0.50);
|
|
|
|
//~ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
|
|
|
//~ cairo_paint (cr);
|
|
|
|
//~
|
|
|
|
//~ cairo_destroy (cr);
|
|
|
|
|
|
|
|
//~ return GTK_WIDGET_CLASS(wrapper_plug_parent_class)->expose_event(widget, event);
|
|
|
|
//~ }
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean |
|
|
|
wrapper_plug_expose_event (GtkWidget *widget, |
|
|
|
GdkEventExpose *event) |
|
|
|
{ |
|
|
|
WrapperPlug *plug = WRAPPER_PLUG (widget); |
|
|
|
cairo_t *cr; |
|
|
|
GdkColor *color; |
|
|
|
|
|
|
|
if (GTK_WIDGET_DRAWABLE (widget) && plug->background_alpha < 1.00) |
|
|
|
{ |
|
|
|
/* create the cairo context */ |
|
|
|
cr = gdk_cairo_create (widget->window); |
|
|
|
|
|
|
|
/* get the background gdk color */ |
|
|
|
color = &(widget->style->bg[GTK_STATE_NORMAL]); |
|
|
|
|
|
|
|
/* set the cairo source color */ |
|
|
|
_set_source_rgba (cr, color, plug->background_alpha); |
|
|
|
|
|
|
|
/* create retangle */ |
|
|
|
cairo_rectangle (cr, event->area.x, event->area.y, |
|
|
|
event->area.width, event->area.height); |
|
|
|
|
|
|
|
/* draw on source */ |
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
|
|
|
|
|
|
|
/* paint rectangle */ |
|
|
|
cairo_fill (cr); |
|
|
|
|
|
|
|
/* destroy cairo context */ |
|
|
|
cairo_destroy (cr); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//~ cairo_rectangle (cr, event->area.x,
|
|
|
|
//~ event->area.y,
|
|
|
|
//~ event->area.width,
|
|
|
|
//~ event->area.height);
|
|
|
|
//~ cairo_clip (cr);
|
|
|
|
//~
|
|
|
|
//~ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
//~
|
|
|
|
//~ style = gtk_widget_get_style (widget);
|
|
|
|
//~ r = (double) style->bg[widget->state].red / (double) 65535;
|
|
|
|
//~ g = (double) style->bg[widget->state].green / (double) 65535;
|
|
|
|
//~ b = (double) style->bg[widget->state].blue / (double) 65535;
|
|
|
|
//~ cairo_set_source_rgba (cr, r, g, b, 0.50);
|
|
|
|
//~ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
|
|
|
//~ cairo_paint (cr);
|
|
|
|
//~
|
|
|
|
//~ cairo_destroy (cr);
|
|
|
|
|
|
|
|
return GTK_WIDGET_CLASS(wrapper_plug_parent_class)->expose_event(widget, event); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -100,10 +129,10 @@ wrapper_plug_class_init (WrapperPlugClass *klass) |
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass); |
|
|
|
gobject_class->finalize = wrapper_plug_finalize; |
|
|
|
|
|
|
|
|
|
|
|
gtkwidget_class = GTK_WIDGET_CLASS (klass); |
|
|
|
gtkwidget_class->client_event = wrapper_plug_client_event; |
|
|
|
//gtkwidget_class->expose_event = wrapper_plug_expose_event;
|
|
|
|
gtkwidget_class->expose_event = wrapper_plug_expose_event; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -113,26 +142,27 @@ wrapper_plug_init (WrapperPlug *plug) |
|
|
|
{ |
|
|
|
plug->socket_id = 0; |
|
|
|
plug->atom = panel_atom_intern ("XFCE_PANEL_PLUGIN"); |
|
|
|
|
|
|
|
//~ GdkScreen *screen;
|
|
|
|
//~ GdkColormap *colormap;
|
|
|
|
//~ GtkWidget *widget = GTK_WIDGET (plug);
|
|
|
|
//~
|
|
|
|
//~ /* try to set the rgba colormap */
|
|
|
|
//~ screen = gtk_window_get_screen (GTK_WINDOW (plug));
|
|
|
|
//~ if (gdk_screen_is_composited (screen))
|
|
|
|
//~ {
|
|
|
|
//~ /* try to get the rgba colormap */
|
|
|
|
//~ colormap = gdk_screen_get_rgba_colormap (screen);
|
|
|
|
//~
|
|
|
|
//~ if (G_LIKELY (colormap))
|
|
|
|
//~ {
|
|
|
|
//~ /* set the colormap */
|
|
|
|
//~ gtk_widget_set_colormap (widget, colormap);
|
|
|
|
//~ }
|
|
|
|
//~ }
|
|
|
|
|
|
|
|
//gtk_widget_set_app_paintable (GTK_WIDGET (plug), TRUE);
|
|
|
|
plug->background_alpha = 1.00; |
|
|
|
|
|
|
|
GdkScreen *screen; |
|
|
|
GdkColormap *colormap; |
|
|
|
GtkWidget *widget = GTK_WIDGET (plug); |
|
|
|
|
|
|
|
/* try to set the rgba colormap */ |
|
|
|
screen = gtk_window_get_screen (GTK_WINDOW (plug)); |
|
|
|
if (gdk_screen_is_composited (screen)) |
|
|
|
{ |
|
|
|
/* try to get the rgba colormap */ |
|
|
|
colormap = gdk_screen_get_rgba_colormap (screen); |
|
|
|
|
|
|
|
if (G_LIKELY (colormap)) |
|
|
|
{ |
|
|
|
/* set the colormap */ |
|
|
|
gtk_widget_set_colormap (widget, colormap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
gtk_widget_set_app_paintable (GTK_WIDGET (plug), TRUE); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -147,56 +177,69 @@ wrapper_plug_finalize (GObject *object) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean |
|
|
|
wrapper_plug_client_event (GtkWidget *widget, |
|
|
|
static gboolean |
|
|
|
wrapper_plug_client_event (GtkWidget *widget, |
|
|
|
GdkEventClient *event) |
|
|
|
{ |
|
|
|
WrapperPlug *plug = WRAPPER_PLUG (widget); |
|
|
|
XfcePanelPluginMessage message; |
|
|
|
glong value; |
|
|
|
|
|
|
|
|
|
|
|
/* check if this is a panel client event */ |
|
|
|
if (G_LIKELY (event->message_type == plug->atom)) |
|
|
|
{ |
|
|
|
/* get message and value */ |
|
|
|
message = event->data.l[0]; |
|
|
|
value = event->data.l[1]; |
|
|
|
|
|
|
|
|
|
|
|
switch (message) |
|
|
|
{ |
|
|
|
case MESSAGE_SET_SENSITIVE: |
|
|
|
/* set the sensitivity of the plug */ |
|
|
|
gtk_widget_set_sensitive (widget, !!(value == 1)); |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case MESSAGE_SET_SIZE: |
|
|
|
/* set the new plugin size */ |
|
|
|
xfce_panel_plugin_provider_set_size (plug->provider, value); |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case MESSAGE_SET_ORIENTATION: |
|
|
|
/* set the plugin orientation */ |
|
|
|
xfce_panel_plugin_provider_set_orientation (plug->provider, value); |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case MESSAGE_SET_SCREEN_POSITION: |
|
|
|
/* set the plugin screen position */ |
|
|
|
xfce_panel_plugin_provider_set_screen_position (plug->provider, value); |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case MESSAGE_SET_BACKGROUND_ALPHA: |
|
|
|
/* set the background alpha */ |
|
|
|
plug->background_alpha = CLAMP (value, 0, 100) / 100.00; |
|
|
|
|
|
|
|
/* redraw the window */ |
|
|
|
gtk_widget_queue_draw (widget); |
|
|
|
break; |
|
|
|
|
|
|
|
case MESSAGE_SAVE: |
|
|
|
/* save the plugin */ |
|
|
|
xfce_panel_plugin_provider_save (plug->provider); |
|
|
|
break; |
|
|
|
|
|
|
|
case MESSAGE_QUIT: |
|
|
|
/* don't send messages */ |
|
|
|
plug->socket_id = 0; |
|
|
|
|
|
|
|
|
|
|
|
/* quit the main loop (destroy plugin) */ |
|
|
|
gtk_main_quit (); |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
g_message ("The wrapper received an unknown message: %d", message); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* we handled the event */ |
|
|
|
return TRUE; |
|
|
|
} |
|
|
@ -216,9 +259,9 @@ wrapper_plug_send_message (WrapperPlug *plug, |
|
|
|
glong value) |
|
|
|
{ |
|
|
|
GdkEventClient event; |
|
|
|
|
|
|
|
|
|
|
|
panel_return_if_fail (WRAPPER_IS_PLUG (plug)); |
|
|
|
|
|
|
|
|
|
|
|
if (G_LIKELY (plug->socket_id > 0)) |
|
|
|
{ |
|
|
|
/* setup the event */ |
|
|
@ -230,16 +273,16 @@ wrapper_plug_send_message (WrapperPlug *plug, |
|
|
|
event.data.l[0] = message; |
|
|
|
event.data.l[1] = value; |
|
|
|
event.data.l[2] = 0; |
|
|
|
|
|
|
|
|
|
|
|
/* don't crash on x errors */ |
|
|
|
gdk_error_trap_push (); |
|
|
|
|
|
|
|
|
|
|
|
/* send the event to the wrapper */ |
|
|
|
gdk_event_send_client_message_for_display (gdk_display_get_default (), (GdkEvent *) &event, plug->socket_id); |
|
|
|
|
|
|
|
|
|
|
|
/* flush the x output buffer */ |
|
|
|
gdk_flush (); |
|
|
|
|
|
|
|
|
|
|
|
/* pop the push */ |
|
|
|
gdk_error_trap_pop (); |
|
|
|
} |
|
|
@ -254,7 +297,7 @@ wrapper_plug_message_expand_changed (XfcePanelPluginProvider *provider, |
|
|
|
{ |
|
|
|
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider)); |
|
|
|
panel_return_if_fail (WRAPPER_IS_PLUG (plug)); |
|
|
|
|
|
|
|
|
|
|
|
/* send signal */ |
|
|
|
wrapper_plug_send_message (plug, MESSAGE_EXPAND_CHANGED, expand ? 1 : 0); |
|
|
|
} |
|
|
@ -267,7 +310,7 @@ wrapper_plug_message_move_item (XfcePanelPluginProvider *provider, |
|
|
|
{ |
|
|
|
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider)); |
|
|
|
panel_return_if_fail (WRAPPER_IS_PLUG (plug)); |
|
|
|
|
|
|
|
|
|
|
|
/* send signal */ |
|
|
|
wrapper_plug_send_message (plug, MESSAGE_MOVE_ITEM, 0); |
|
|
|
} |
|
|
@ -280,7 +323,7 @@ wrapper_plug_message_add_new_items (XfcePanelPluginProvider *provider, |
|
|
|
{ |
|
|
|
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider)); |
|
|
|
panel_return_if_fail (WRAPPER_IS_PLUG (plug)); |
|
|
|
|
|
|
|
|
|
|
|
/* send signal */ |
|
|
|
wrapper_plug_send_message (plug, MESSAGE_ADD_NEW_ITEMS, 0); |
|
|
|
} |
|
|
@ -293,7 +336,7 @@ wrapper_plug_message_customize_panel (XfcePanelPluginProvider *provider, |
|
|
|
{ |
|
|
|
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider)); |
|
|
|
panel_return_if_fail (WRAPPER_IS_PLUG (plug)); |
|
|
|
|
|
|
|
|
|
|
|
/* send signal */ |
|
|
|
wrapper_plug_send_message (plug, MESSAGE_CUSTOMIZE_PANEL, 0); |
|
|
|
} |
|
|
@ -311,7 +354,7 @@ wrapper_plug_message_remove (XfcePanelPluginProvider *provider, |
|
|
|
{ |
|
|
|
/* send signal */ |
|
|
|
wrapper_plug_send_message (plug, MESSAGE_REMOVE, 0); |
|
|
|
|
|
|
|
|
|
|
|
/* quit the wrapper */ |
|
|
|
gtk_main_quit (); |
|
|
|
} |
|
|
@ -324,26 +367,26 @@ wrapper_plug_new (GdkNativeWindow socket_id, |
|
|
|
XfcePanelPluginProvider *provider) |
|
|
|
{ |
|
|
|
WrapperPlug *plug; |
|
|
|
|
|
|
|
|
|
|
|
/* create new object */ |
|
|
|
plug = g_object_new (WRAPPER_TYPE_PLUG, NULL); |
|
|
|
|
|
|
|
|
|
|
|
/* store info */ |
|
|
|
plug->socket_id = socket_id; |
|
|
|
plug->provider = provider; |
|
|
|
|
|
|
|
|
|
|
|
/* monitor changes in the provider */ |
|
|
|
g_signal_connect (G_OBJECT (provider), "expand-changed", G_CALLBACK (wrapper_plug_message_expand_changed), plug); |
|
|
|
g_signal_connect (G_OBJECT (provider), "move-item", G_CALLBACK (wrapper_plug_message_move_item), plug); |
|
|
|
g_signal_connect (G_OBJECT (provider), "add-new-items", G_CALLBACK (wrapper_plug_message_add_new_items), plug); |
|
|
|
g_signal_connect (G_OBJECT (provider), "customize-panel", G_CALLBACK (wrapper_plug_message_customize_panel), plug); |
|
|
|
g_signal_connect (G_OBJECT (provider), "destroy", G_CALLBACK (wrapper_plug_message_remove), plug); |
|
|
|
|
|
|
|
|
|
|
|
/* contruct the plug */ |
|
|
|
gtk_plug_construct (GTK_PLUG (plug), socket_id); |
|
|
|
|
|
|
|
|
|
|
|
/* send the plug id back to the panel */ |
|
|
|
wrapper_plug_send_message (plug, MESSAGE_SET_PLUG_ID, gtk_plug_get_id (GTK_PLUG (plug))); |
|
|
|
|
|
|
|
|
|
|
|
return GTK_WIDGET (plug); |
|
|
|
} |
|
|
|