[Xfce4-commits] <xfce4-panel:nick/gtk3> Systray: Ported to Gtk3
Andrzej
noreply at xfce.org
Fri Apr 12 00:24:02 CEST 2013
Updating branch refs/heads/nick/gtk3
to 3ad863389f96b218ff286c922b091473b8cda1b6 (commit)
from dfa591b84694c5d2bb8b8c534359da9281e35d6a (commit)
commit 3ad863389f96b218ff286c922b091473b8cda1b6
Author: Andrzej <ndrwrdck at gmail.com>
Date: Thu Apr 11 23:22:27 2013 +0100
Systray: Ported to Gtk3
Quite a few problems mostly related to API removed from Gdk.
Marked as "FIXME".
plugins/systray/systray-box.c | 190 +++++++++++++++++++++++--------------
plugins/systray/systray-manager.c | 50 +++++-----
plugins/systray/systray-socket.c | 134 ++++++++++++++-------------
plugins/systray/systray-socket.h | 5 +-
plugins/systray/systray.c | 92 +++++++++---------
5 files changed, 263 insertions(+), 208 deletions(-)
diff --git a/plugins/systray/systray-box.c b/plugins/systray/systray-box.c
index c5183da..5505ec5 100644
--- a/plugins/systray/systray-box.c
+++ b/plugins/systray/systray-box.c
@@ -48,8 +48,15 @@ static void systray_box_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static void systray_box_finalize (GObject *object);
-static void systray_box_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
+static void systray_box_get_preferred_length (GtkWidget *widget,
+ gint *minimum_length,
+ gint *natural_length);
+static void systray_box_get_preferred_width (GtkWidget *widget,
+ gint *minimum_width,
+ gint *natural_width);
+static void systray_box_get_preferred_height (GtkWidget *widget,
+ gint *minimum_height,
+ gint *natural_height);
static void systray_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void systray_box_add (GtkContainer *container,
@@ -119,7 +126,8 @@ systray_box_class_init (SystrayBoxClass *klass)
gobject_class->finalize = systray_box_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
- gtkwidget_class->size_request = systray_box_size_request;
+ gtkwidget_class->get_preferred_width = systray_box_get_preferred_width;
+ gtkwidget_class->get_preferred_height = systray_box_get_preferred_height;
gtkwidget_class->size_allocate = systray_box_size_allocate;
gtkcontainer_class = GTK_CONTAINER_CLASS (klass);
@@ -201,12 +209,16 @@ systray_box_size_get_max_child_size (SystrayBox *box,
gint *row_size_ret,
gint *offset_ret)
{
- GtkWidget *widget = GTK_WIDGET (box);
- gint size;
- gint rows;
- gint row_size;
+ GtkWidget *widget = GTK_WIDGET (box);
+ gint size;
+ gint rows;
+ gint row_size;
+ GtkStyleContext *ctx;
+ GtkBorder padding;
- alloc_size -= 2 * GTK_CONTAINER (widget)->border_width;
+ ctx = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_padding (ctx, gtk_widget_get_state_flags (widget), &padding);
+ alloc_size -= MAX (padding.left+padding.right, padding.top+padding.bottom);
/* count the number of rows that fit in the allocated space */
for (rows = 1;; rows++)
@@ -243,24 +255,67 @@ systray_box_size_get_max_child_size (SystrayBox *box,
static void
-systray_box_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+systray_box_get_preferred_width (GtkWidget *widget,
+ gint *minimum_width,
+ gint *natural_width)
{
SystrayBox *box = XFCE_SYSTRAY_BOX (widget);
- GtkWidget *child;
- gint border;
- GtkRequisition child_req;
- gint n_hidden_childeren = 0;
- gint rows;
- gdouble cols;
- gint row_size;
- gdouble cells;
- gint min_seq_cells = -1;
- gdouble ratio;
- GSList *li;
- gboolean hidden;
- gint col_px;
- gint row_px;
+
+ if (box->horizontal)
+ {
+ systray_box_get_preferred_length (widget, minimum_width, natural_width);
+ }
+ else
+ {
+ if (minimum_width != NULL)
+ *minimum_width = -1;
+ if (natural_width != NULL)
+ *natural_width = -1;
+ }
+}
+
+
+static void
+systray_box_get_preferred_height (GtkWidget *widget,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ SystrayBox *box = XFCE_SYSTRAY_BOX (widget);
+
+ if (box->horizontal)
+ {
+ if (minimum_height != NULL)
+ *minimum_height = -1;
+ if (natural_height != NULL)
+ *natural_height = -1;
+ }
+ else
+ {
+ systray_box_get_preferred_length (widget, minimum_height, natural_height);
+ }
+}
+
+
+static void
+systray_box_get_preferred_length (GtkWidget *widget,
+ gint *minimum_length,
+ gint *natural_length)
+{
+ SystrayBox *box = XFCE_SYSTRAY_BOX (widget);
+ GtkWidget *child;
+ GtkRequisition child_req;
+ gint n_hidden_childeren = 0;
+ gint rows;
+ gdouble cols;
+ gint row_size;
+ gdouble cells;
+ gint min_seq_cells = -1;
+ gdouble ratio;
+ GSList *li;
+ gboolean hidden;
+ gint length;
+ GtkStyleContext *ctx;
+ GtkBorder padding;
box->n_visible_children = 0;
@@ -272,11 +327,11 @@ systray_box_size_request (GtkWidget *widget,
child = GTK_WIDGET (li->data);
panel_return_if_fail (XFCE_IS_SYSTRAY_SOCKET (child));
- gtk_widget_size_request (child, &child_req);
+ gtk_widget_get_preferred_size (child, NULL, &child_req);
/* skip invisible requisitions (see macro) or hidden widgets */
if (REQUISITION_IS_INVISIBLE (child_req)
- || !GTK_WIDGET_VISIBLE (child))
+ || !gtk_widget_get_visible (child))
continue;
hidden = systray_socket_get_hidden (XFCE_SYSTRAY_SOCKET (child));
@@ -335,24 +390,11 @@ systray_box_size_request (GtkWidget *widget,
if (min_seq_cells != -1)
cols = MAX (min_seq_cells, cols);
- col_px = row_size * cols + (cols - 1) * SPACING;
- row_px = row_size * rows + (rows - 1) * SPACING;
-
- if (box->horizontal)
- {
- requisition->width = col_px;
- requisition->height = row_px;
- }
- else
- {
- requisition->width = row_px;
- requisition->height = col_px;
- }
+ length = row_size * cols + (cols - 1) * SPACING;
}
else
{
- requisition->width = 0;
- requisition->height = 0;
+ length = 0;
}
/* emit property if changed */
@@ -367,9 +409,15 @@ systray_box_size_request (GtkWidget *widget,
}
/* add border size */
- border = GTK_CONTAINER (widget)->border_width * 2;
- requisition->width += border;
- requisition->height += border;
+ ctx = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_padding (ctx, gtk_widget_get_state_flags (widget), &padding);
+ length += MAX (padding.left+padding.right, padding.top+padding.bottom);
+
+ if (minimum_length != NULL)
+ *minimum_length = length;
+
+ if (natural_length != NULL)
+ *natural_length = length;
}
@@ -378,24 +426,26 @@ static void
systray_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
- SystrayBox *box = XFCE_SYSTRAY_BOX (widget);
- GtkWidget *child;
- GtkAllocation child_alloc;
- GtkRequisition child_req;
- gint border;
- gint rows;
- gint row_size;
- gdouble ratio;
- gint x, x_start, x_end;
- gint y, y_start, y_end;
- gint offset;
- GSList *li;
- gint alloc_size;
- gint idx;
-
- widget->allocation = *allocation;
-
- border = GTK_CONTAINER (widget)->border_width;
+ SystrayBox *box = XFCE_SYSTRAY_BOX (widget);
+ GtkWidget *child;
+ GtkAllocation child_alloc;
+ GtkRequisition child_req;
+ gint rows;
+ gint row_size;
+ gdouble ratio;
+ gint x, x_start, x_end;
+ gint y, y_start, y_end;
+ gint offset;
+ GSList *li;
+ gint alloc_size;
+ gint idx;
+ GtkStyleContext *ctx;
+ GtkBorder padding;
+
+ gtk_widget_set_allocation (widget, allocation);
+
+ ctx = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_padding (ctx, gtk_widget_get_state_flags (widget), &padding);
alloc_size = box->horizontal ? allocation->height : allocation->width;
@@ -403,14 +453,14 @@ systray_box_size_allocate (GtkWidget *widget,
panel_debug_filtered (PANEL_DEBUG_SYSTRAY, "allocate rows=%d, row_size=%d, w=%d, h=%d, horiz=%s, border=%d",
rows, row_size, allocation->width, allocation->height,
- PANEL_DEBUG_BOOL (box->horizontal), border);
+ PANEL_DEBUG_BOOL (box->horizontal), padding.left);
/* get allocation bounds */
- x_start = allocation->x + border;
- x_end = allocation->x + allocation->width - border;
+ x_start = allocation->x + padding.left;
+ x_end = allocation->x + allocation->width - padding.right;
- y_start = allocation->y + border;
- y_end = allocation->y + allocation->height - border;
+ y_start = allocation->y + padding.top;
+ y_end = allocation->y + allocation->height - padding.bottom;
/* add offset to center the tray contents */
if (box->horizontal)
@@ -428,10 +478,10 @@ systray_box_size_allocate (GtkWidget *widget,
child = GTK_WIDGET (li->data);
panel_return_if_fail (XFCE_IS_SYSTRAY_SOCKET (child));
- if (!GTK_WIDGET_VISIBLE (child))
+ if (!gtk_widget_get_visible (child))
continue;
- gtk_widget_get_child_requisition (child, &child_req);
+ gtk_widget_get_preferred_size (child, NULL, &child_req);
if (REQUISITION_IS_INVISIBLE (child_req)
|| (!box->show_hidden
@@ -572,7 +622,7 @@ systray_box_add (GtkContainer *container,
panel_return_if_fail (XFCE_IS_SYSTRAY_BOX (box));
panel_return_if_fail (GTK_IS_WIDGET (child));
- panel_return_if_fail (child->parent == NULL);
+ panel_return_if_fail (gtk_widget_get_parent (child) == NULL);
box->childeren = g_slist_insert_sorted (box->childeren, child,
systray_box_compare_function);
diff --git a/plugins/systray/systray-manager.c b/plugins/systray/systray-manager.c
index d77faee..7402b70 100644
--- a/plugins/systray/systray-manager.c
+++ b/plugins/systray/systray-manager.c
@@ -343,10 +343,11 @@ systray_manager_register (SystrayManager *manager,
systray_manager_set_visual (manager);
/* get the current x server time stamp */
- timestamp = gdk_x11_get_server_time (invisible->window);
+ timestamp = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (invisible)));
/* try to become the selection owner of this display */
- succeed = gdk_selection_owner_set_for_display (display, invisible->window,
+ succeed = gdk_selection_owner_set_for_display (display,
+ gtk_widget_get_window (GTK_WIDGET (invisible)),
manager->selection_atom,
timestamp, TRUE);
@@ -363,7 +364,7 @@ systray_manager_register (SystrayManager *manager,
xevent.data.l[0] = timestamp;
xevent.data.l[1] = gdk_x11_atom_to_xatom_for_display (display,
manager->selection_atom);
- xevent.data.l[2] = GDK_WINDOW_XWINDOW (invisible->window);
+ xevent.data.l[2] = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (invisible)));
xevent.data.l[3] = 0;
xevent.data.l[4] = 0;
@@ -372,20 +373,23 @@ systray_manager_register (SystrayManager *manager,
False, StructureNotifyMask, (XEvent *)&xevent);
/* system_tray_request_dock and selectionclear */
- gdk_window_add_filter (invisible->window, systray_manager_window_filter, manager);
+ gdk_window_add_filter (gtk_widget_get_window (GTK_WIDGET (invisible)),
+ systray_manager_window_filter, manager);
/* get the opcode atom (for both gdk and x11) */
opcode_atom = gdk_atom_intern ("_NET_SYSTEM_TRAY_OPCODE", FALSE);
manager->opcode_atom = gdk_x11_atom_to_xatom_for_display (display, opcode_atom);
/* system_tray_begin_message and system_tray_cancel_message */
- gdk_display_add_client_message_filter (display,
- opcode_atom, systray_manager_handle_client_message_opcode, manager);
+ // FIXME
+ //gdk_display_add_client_message_filter (display,
+ // opcode_atom, systray_manager_handle_client_message_opcode, manager);
/* _net_system_tray_message_data */
- gdk_display_add_client_message_filter (display,
- gdk_atom_intern ("_NET_SYSTEM_TRAY_MESSAGE_DATA", FALSE),
- systray_manager_handle_client_message_message_data, manager);
+ // FIXME
+ //gdk_display_add_client_message_filter (display,
+ // gdk_atom_intern ("_NET_SYSTEM_TRAY_MESSAGE_DATA", FALSE),
+ // systray_manager_handle_client_message_message_data, manager);
panel_debug (PANEL_DEBUG_SYSTRAY, "registered manager on screen %d", screen_number);
}
@@ -441,24 +445,24 @@ systray_manager_unregister (SystrayManager *manager)
return;
panel_return_if_fail (GTK_IS_INVISIBLE (invisible));
- panel_return_if_fail (GTK_WIDGET_REALIZED (invisible));
- panel_return_if_fail (GDK_IS_WINDOW (invisible->window));
+ panel_return_if_fail (gtk_widget_get_realized (invisible));
+ panel_return_if_fail (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (invisible))));
/* get the display of the invisible window */
display = gtk_widget_get_display (invisible);
/* remove our handling of the selection if we're the owner */
owner = gdk_selection_owner_get_for_display (display, manager->selection_atom);
- if (owner == invisible->window)
+ if (owner == gtk_widget_get_window (GTK_WIDGET (invisible)))
{
gdk_selection_owner_set_for_display (display, NULL,
manager->selection_atom,
- gdk_x11_get_server_time (invisible->window),
+ gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (invisible))),
TRUE);
}
/* remove window filter */
- gdk_window_remove_filter (invisible->window,
+ gdk_window_remove_filter (gtk_widget_get_window (GTK_WIDGET (invisible)),
systray_manager_window_filter, manager);
/* remove all sockets from the hash table */
@@ -659,7 +663,7 @@ systray_manager_handle_cancel_message (SystrayManager *manager,
XClientMessageEvent *xevent)
{
GtkSocket *socket;
- GdkNativeWindow window = xevent->data.l[2];
+ Window window = xevent->data.l[2];
panel_return_if_fail (XFCE_IS_SYSTRAY_MANAGER (manager));
@@ -683,7 +687,7 @@ systray_manager_handle_dock_request (SystrayManager *manager,
{
GtkWidget *socket;
GdkScreen *screen;
- GdkNativeWindow window = xevent->data.l[2];
+ Window window = xevent->data.l[2];
panel_return_if_fail (XFCE_IS_SYSTRAY_MANAGER (manager));
panel_return_if_fail (GTK_IS_INVISIBLE (manager->invisible));
@@ -732,7 +736,7 @@ systray_manager_handle_undock_request (GtkSocket *socket,
gpointer user_data)
{
SystrayManager *manager = XFCE_SYSTRAY_MANAGER (user_data);
- GdkNativeWindow *window;
+ Window *window;
panel_return_val_if_fail (XFCE_IS_SYSTRAY_MANAGER (manager), FALSE);
@@ -756,12 +760,11 @@ systray_manager_set_visual (SystrayManager *manager)
Visual *xvisual;
Atom visual_atom;
gulong data[1];
- GdkColormap *colormap;
GdkScreen *screen;
panel_return_if_fail (XFCE_IS_SYSTRAY_MANAGER (manager));
panel_return_if_fail (GTK_IS_INVISIBLE (manager->invisible));
- panel_return_if_fail (GDK_IS_WINDOW (manager->invisible->window));
+ panel_return_if_fail (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (manager->invisible))));
/* get invisible display and screen */
display = gtk_widget_get_display (manager->invisible);
@@ -781,13 +784,12 @@ systray_manager_set_visual (SystrayManager *manager)
else
{
/* use the default visual for the screen */
- colormap = gdk_screen_get_default_colormap (screen);
- xvisual = GDK_VISUAL_XVISUAL (gdk_colormap_get_visual (colormap));
+ xvisual = GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (screen));
}
data[0] = XVisualIDFromVisual (xvisual);
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
- GDK_WINDOW_XWINDOW (manager->invisible->window),
+ GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (manager->invisible))),
visual_atom,
XA_VISUALID, 32,
PropModeReplace,
@@ -806,7 +808,7 @@ systray_manager_set_orientation (SystrayManager *manager,
panel_return_if_fail (XFCE_IS_SYSTRAY_MANAGER (manager));
panel_return_if_fail (GTK_IS_INVISIBLE (manager->invisible));
- panel_return_if_fail (GDK_IS_WINDOW (manager->invisible->window));
+ panel_return_if_fail (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (manager->invisible))));
/* set the new orientation */
manager->orientation = orientation;
@@ -825,7 +827,7 @@ systray_manager_set_orientation (SystrayManager *manager,
/* change the x property */
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
- GDK_WINDOW_XWINDOW (manager->invisible->window),
+ GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (manager->invisible))),
orientation_atom,
XA_CARDINAL, 32,
PropModeReplace,
diff --git a/plugins/systray/systray-socket.c b/plugins/systray/systray-socket.c
index 43423bb..18dcc0d 100644
--- a/plugins/systray/systray-socket.c
+++ b/plugins/systray/systray-socket.c
@@ -53,7 +53,7 @@ struct _SystraySocket
GtkSocket __parent__;
/* plug window */
- GdkNativeWindow window;
+ Window window;
gchar *name;
@@ -68,8 +68,8 @@ static void systray_socket_finalize (GObject *object);
static void systray_socket_realize (GtkWidget *widget);
static void systray_socket_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static gboolean systray_socket_expose_event (GtkWidget *widget,
- GdkEventExpose *event);
+static gboolean systray_socket_draw (GtkWidget *widget,
+ cairo_t *cr);
static void systray_socket_style_set (GtkWidget *widget,
GtkStyle *previous_style);
@@ -91,7 +91,7 @@ systray_socket_class_init (SystraySocketClass *klass)
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->realize = systray_socket_realize;
gtkwidget_class->size_allocate = systray_socket_size_allocate;
- gtkwidget_class->expose_event = systray_socket_expose_event;
+ gtkwidget_class->draw = systray_socket_draw;
gtkwidget_class->style_set = systray_socket_style_set;
}
@@ -122,7 +122,7 @@ static void
systray_socket_realize (GtkWidget *widget)
{
SystraySocket *socket = XFCE_SYSTRAY_SOCKET (widget);
- GdkColor transparent = { 0, 0, 0, 0 };
+ GdkRGBA transparent = { 0.0, 0.0, 0.0, 0.0 };
GdkWindow *window;
GTK_WIDGET_CLASS (systray_socket_parent_class)->realize (widget);
@@ -131,18 +131,19 @@ systray_socket_realize (GtkWidget *widget)
if (socket->is_composited)
{
- gdk_window_set_background (window, &transparent);
+ gdk_window_set_background_rgba (window, &transparent);
gdk_window_set_composited (window, TRUE);
socket->parent_relative_bg = FALSE;
}
- else if (gtk_widget_get_visual (widget) ==
- gdk_drawable_get_visual (GDK_DRAWABLE (gdk_window_get_parent (window))))
- {
- gdk_window_set_back_pixmap (window, NULL, TRUE);
-
- socket->parent_relative_bg = TRUE;
- }
+ // FIXME
+ //else if (gtk_widget_get_visual (widget) ==
+ // gdk_drawable_get_visual (GDK_DRAWABLE (gdk_window_get_parent (window))))
+ // {
+ // gdk_window_set_back_pixmap (window, NULL, TRUE);
+ //
+ // socket->parent_relative_bg = TRUE;
+ // }
else
{
socket->parent_relative_bg = FALSE;
@@ -169,27 +170,32 @@ systray_socket_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
SystraySocket *socket = XFCE_SYSTRAY_SOCKET (widget);
- gboolean moved = allocation->x != widget->allocation.x
- || allocation->y != widget->allocation.y;
- gboolean resized = allocation->width != widget->allocation.width
- ||allocation->height != widget->allocation.height;
+ GtkAllocation widget_allocation;
+ gboolean moved;
+ gboolean resized;
+
+ gtk_widget_get_allocation (widget, &widget_allocation);
+ moved = allocation->x != widget_allocation.x
+ || allocation->y != widget_allocation.y;
+ resized = allocation->width != widget_allocation.width
+ ||allocation->height != widget_allocation.height;
if ((moved || resized)
- && GTK_WIDGET_MAPPED (widget))
+ && gtk_widget_get_mapped (widget))
{
if (socket->is_composited)
- gdk_window_invalidate_rect (gdk_window_get_parent (widget->window),
- &widget->allocation, FALSE);
+ gdk_window_invalidate_rect (gdk_window_get_parent (gtk_widget_get_window (widget)),
+ &widget_allocation, FALSE);
}
GTK_WIDGET_CLASS (systray_socket_parent_class)->size_allocate (widget, allocation);
if ((moved || resized)
- && GTK_WIDGET_MAPPED (widget))
+ && gtk_widget_get_mapped (widget))
{
if (socket->is_composited)
- gdk_window_invalidate_rect (gdk_window_get_parent (widget->window),
- &widget->allocation, FALSE);
+ gdk_window_invalidate_rect (gdk_window_get_parent (gtk_widget_get_window (widget)),
+ &widget_allocation, FALSE);
else if (moved && socket->parent_relative_bg)
systray_socket_force_redraw (socket);
}
@@ -198,30 +204,24 @@ systray_socket_size_allocate (GtkWidget *widget,
static gboolean
-systray_socket_expose_event (GtkWidget *widget,
- GdkEventExpose *event)
+systray_socket_draw (GtkWidget *widget,
+ cairo_t *cr)
{
SystraySocket *socket = XFCE_SYSTRAY_SOCKET (widget);
- cairo_t *cr;
if (socket->is_composited)
{
/* clear to transparent */
- cr = gdk_cairo_create (widget->window);
cairo_set_source_rgba (cr, 0, 0, 0, 0);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- gdk_cairo_region (cr, event->region);
cairo_fill (cr);
- cairo_destroy (cr);
}
else if (socket->parent_relative_bg)
{
/* clear to parent-relative pixmap */
- gdk_window_clear_area (widget->window,
- event->area.x,
- event->area.y,
- event->area.width,
- event->area.height);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_fill (cr);
}
return FALSE;
@@ -239,15 +239,15 @@ systray_socket_style_set (GtkWidget *widget,
GtkWidget *
systray_socket_new (GdkScreen *screen,
- GdkNativeWindow window)
+ Window window)
{
SystraySocket *socket;
GdkDisplay *display;
XWindowAttributes attr;
gint result;
GdkVisual *visual;
- GdkColormap *colormap;
- gboolean release_colormap = FALSE;
+ //GdkColormap *colormap; //FIXME
+ //gboolean release_colormap = FALSE;
panel_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
@@ -268,33 +268,36 @@ systray_socket_new (GdkScreen *screen,
return NULL;
/* get the correct colormap */
- if (visual == gdk_screen_get_rgb_visual (screen))
- colormap = gdk_screen_get_rgb_colormap (screen);
- else if (visual == gdk_screen_get_rgba_visual (screen))
- colormap = gdk_screen_get_rgba_colormap (screen);
- else if (visual == gdk_screen_get_system_visual (screen))
- colormap = gdk_screen_get_system_colormap (screen);
- else
- {
- /* create custom colormap */
- colormap = gdk_colormap_new (visual, FALSE);
- release_colormap = TRUE;
- }
+ // FIXME
+ //if (visual == gdk_screen_get_rgb_visual (screen))
+ // colormap = gdk_screen_get_rgb_colormap (screen);
+ //else if (visual == gdk_screen_get_rgba_visual (screen))
+ // colormap = gdk_screen_get_rgba_colormap (screen);
+ //else if (visual == gdk_screen_get_system_visual (screen))
+ // colormap = gdk_screen_get_system_colormap (screen);
+ //else
+ // {
+ // /* create custom colormap */
+ // colormap = gdk_colormap_new (visual, FALSE);
+ // release_colormap = TRUE;
+ // }
/* create a new socket */
socket = g_object_new (XFCE_TYPE_SYSTRAY_SOCKET, NULL);
socket->window = window;
socket->is_composited = FALSE;
- gtk_widget_set_colormap (GTK_WIDGET (socket), colormap);
+ //gtk_widget_set_colormap (GTK_WIDGET (socket), colormap); //FIXME
/* release the custom colormap */
- if (release_colormap)
- g_object_unref (G_OBJECT (colormap));
+ // FIXME
+ //if (release_colormap)
+ // g_object_unref (G_OBJECT (colormap));
/* check if there is an alpha channel in the visual */
- if (visual->red_prec + visual->blue_prec + visual->green_prec < visual->depth
- && gdk_display_supports_composite (gdk_screen_get_display (screen)))
- socket->is_composited = TRUE;
+ // FIXME
+ //if (visual->red_prec + visual->blue_prec + visual->green_prec < visual->depth
+ // && gdk_display_supports_composite (gdk_screen_get_display (screen)))
+ // socket->is_composited = TRUE;
return GTK_WIDGET (socket);
}
@@ -304,22 +307,25 @@ systray_socket_new (GdkScreen *screen,
void
systray_socket_force_redraw (SystraySocket *socket)
{
- GtkWidget *widget = GTK_WIDGET (socket);
- XEvent xev;
- GdkDisplay *display;
+ GtkWidget *widget = GTK_WIDGET (socket);
+ XEvent xev;
+ GdkDisplay *display;
+ GtkAllocation allocation;
panel_return_if_fail (XFCE_IS_SYSTRAY_SOCKET (socket));
- if (GTK_WIDGET_MAPPED (socket) && socket->parent_relative_bg)
+ if (gtk_widget_get_mapped (widget) && socket->parent_relative_bg)
{
display = gtk_widget_get_display (widget);
+ gtk_widget_get_allocation (widget, &allocation);
+
xev.xexpose.type = Expose;
- xev.xexpose.window = GDK_WINDOW_XWINDOW (GTK_SOCKET (socket)->plug_window);
+ xev.xexpose.window = GDK_WINDOW_XID (gtk_socket_get_plug_window (GTK_SOCKET (socket)));
xev.xexpose.x = 0;
xev.xexpose.y = 0;
- xev.xexpose.width = widget->allocation.width;
- xev.xexpose.height = widget->allocation.height;
+ xev.xexpose.width = allocation.width;
+ xev.xexpose.height = allocation.height;
xev.xexpose.count = 0;
gdk_error_trap_push ();
@@ -331,7 +337,7 @@ systray_socket_force_redraw (SystraySocket *socket)
* since that is asynchronous.
*/
XSync (GDK_DISPLAY_XDISPLAY (display), False);
- gdk_error_trap_pop ();
+ gdk_error_trap_pop_ignored ();
}
}
@@ -421,7 +427,7 @@ systray_socket_get_name (SystraySocket *socket)
-GdkNativeWindow *
+Window *
systray_socket_get_window (SystraySocket *socket)
{
panel_return_val_if_fail (XFCE_IS_SYSTRAY_SOCKET (socket), NULL);
diff --git a/plugins/systray/systray-socket.h b/plugins/systray/systray-socket.h
index 619eb99..8d9ccbd 100644
--- a/plugins/systray/systray-socket.h
+++ b/plugins/systray/systray-socket.h
@@ -23,6 +23,7 @@
#define __SYSTRAY_SOCKET_H__
#include <gtk/gtk.h>
+#include <gtk/gtkx.h>
typedef struct _SystraySocketClass SystraySocketClass;
typedef struct _SystraySocket SystraySocket;
@@ -39,7 +40,7 @@ GType systray_socket_get_type (void) G_GNUC_CONST;
void systray_socket_register_type (GTypeModule *type_module);
GtkWidget *systray_socket_new (GdkScreen *screen,
- GdkNativeWindow window) G_GNUC_MALLOC;
+ Window window) G_GNUC_MALLOC;
void systray_socket_force_redraw (SystraySocket *socket);
@@ -47,7 +48,7 @@ gboolean systray_socket_is_composited (SystraySocket *socket);
const gchar *systray_socket_get_name (SystraySocket *socket);
-GdkNativeWindow *systray_socket_get_window (SystraySocket *socket);
+Window *systray_socket_get_window (SystraySocket *socket);
gboolean systray_socket_get_hidden (SystraySocket *socket);
diff --git a/plugins/systray/systray.c b/plugins/systray/systray.c
index 2095bc0..0d85fb3 100644
--- a/plugins/systray/systray.c
+++ b/plugins/systray/systray.c
@@ -54,8 +54,8 @@ static void systray_plugin_orientation_changed (XfcePanelPlugin
static gboolean systray_plugin_size_changed (XfcePanelPlugin *panel_plugin,
gint size);
static void systray_plugin_configure_plugin (XfcePanelPlugin *panel_plugin);
-static void systray_plugin_box_expose_event (GtkWidget *box,
- GdkEventExpose *event);
+static void systray_plugin_box_draw (GtkWidget *box,
+ cairo_t *cr);
static void systray_plugin_button_toggled (GtkWidget *button,
SystrayPlugin *plugin);
static void systray_plugin_button_set_arrow (SystrayPlugin *plugin);
@@ -210,7 +210,7 @@ systray_plugin_class_init (SystrayPluginClass *klass)
static void
systray_plugin_init (SystrayPlugin *plugin)
{
- GtkRcStyle *style;
+ //GtkRcStyle *style;
plugin->manager = NULL;
plugin->show_frame = TRUE;
@@ -222,10 +222,11 @@ systray_plugin_init (SystrayPlugin *plugin)
gtk_frame_set_shadow_type (GTK_FRAME (plugin->frame), GTK_SHADOW_ETCHED_IN);
gtk_widget_show (plugin->frame);
- style = gtk_rc_style_new ();
- style->xthickness = style->ythickness = 1;
- gtk_widget_modify_style (plugin->frame, style);
- g_object_unref (G_OBJECT (style));
+ // FIXME
+ //style = gtk_rc_style_new ();
+ //style->xthickness = style->ythickness = 1;
+ //gtk_widget_modify_style (plugin->frame, style);
+ //g_object_unref (G_OBJECT (style));
plugin->hvbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
gtk_container_add (GTK_CONTAINER (plugin->frame), plugin->hvbox);
@@ -233,8 +234,8 @@ systray_plugin_init (SystrayPlugin *plugin)
plugin->box = systray_box_new ();
gtk_box_pack_start (GTK_BOX (plugin->hvbox), plugin->box, TRUE, TRUE, 0);
- g_signal_connect (G_OBJECT (plugin->box), "expose-event",
- G_CALLBACK (systray_plugin_box_expose_event), NULL);
+ g_signal_connect (G_OBJECT (plugin->box), "draw",
+ G_CALLBACK (systray_plugin_box_draw), NULL);
gtk_container_set_border_width (GTK_CONTAINER (plugin->box), FRAME_SPACING);
gtk_widget_show (plugin->box);
@@ -306,7 +307,7 @@ systray_plugin_set_property (GObject *object,
const GValue *tmp;
gchar *name;
guint i;
- GtkRcStyle *style;
+ //GtkRcStyle *style;
switch (prop_id)
{
@@ -323,10 +324,11 @@ systray_plugin_set_property (GObject *object,
gtk_frame_set_shadow_type (GTK_FRAME (plugin->frame),
show_frame ? GTK_SHADOW_ETCHED_IN : GTK_SHADOW_NONE);
- style = gtk_rc_style_new ();
- style->xthickness = style->ythickness = show_frame ? 1 : 0;
- gtk_widget_modify_style (plugin->frame, style);
- g_object_unref (G_OBJECT (style));
+ // FIXME
+ //style = gtk_rc_style_new ();
+ //style->xthickness = style->ythickness = show_frame ? 1 : 0;
+ //gtk_widget_modify_style (plugin->frame, style);
+ //g_object_unref (G_OBJECT (style));
systray_plugin_size_changed (XFCE_PANEL_PLUGIN (plugin),
xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin)));
@@ -375,8 +377,6 @@ systray_plugin_screen_changed_idle (gpointer user_data)
GdkScreen *screen;
GError *error = NULL;
- GDK_THREADS_ENTER ();
-
/* create a new manager and register this screen */
plugin->manager = systray_manager_new ();
g_signal_connect (G_OBJECT (plugin->manager), "icon-added",
@@ -400,8 +400,6 @@ systray_plugin_screen_changed_idle (gpointer user_data)
g_error_free (error);
}
- GDK_THREADS_LEAVE ();
-
return FALSE;
}
@@ -431,8 +429,8 @@ systray_plugin_screen_changed (GtkWidget *widget,
/* schedule a delayed startup */
if (plugin->idle_startup == 0)
- plugin->idle_startup = g_idle_add_full (G_PRIORITY_LOW, systray_plugin_screen_changed_idle,
- plugin, systray_plugin_screen_changed_idle_destroyed);
+ plugin->idle_startup = gdk_threads_add_idle_full (G_PRIORITY_LOW, systray_plugin_screen_changed_idle,
+ plugin, systray_plugin_screen_changed_idle_destroyed);
}
@@ -526,9 +524,11 @@ static gboolean
systray_plugin_size_changed (XfcePanelPlugin *panel_plugin,
gint size)
{
- SystrayPlugin *plugin = XFCE_SYSTRAY_PLUGIN (panel_plugin);
- GtkWidget *frame = plugin->frame;
- gint border = 0;
+ SystrayPlugin *plugin = XFCE_SYSTRAY_PLUGIN (panel_plugin);
+ GtkWidget *frame = plugin->frame;
+ gint border = 0;
+ GtkStyleContext *ctx;
+ GtkBorder padding;
/* set the frame border */
if (plugin->show_frame && size > 26)
@@ -539,8 +539,12 @@ systray_plugin_size_changed (XfcePanelPlugin *panel_plugin,
* behind the allocated size when resizing and during startup, we
* correct the maximum size set by the user with the size the panel
* will most likely allocated */
- border += MAX (frame->style->xthickness, frame->style->ythickness);
- systray_box_set_size_alloc (XFCE_SYSTRAY_BOX (plugin->box), size - 2 * border);
+
+ ctx = gtk_widget_get_style_context (frame);
+ gtk_style_context_get_padding (ctx, gtk_widget_get_state_flags (frame), &padding);
+
+ border += MAX (padding.left+padding.right, padding.top+padding.bottom);
+ systray_box_set_size_alloc (XFCE_SYSTRAY_BOX (plugin->box), size - border);
return TRUE;
}
@@ -595,21 +599,22 @@ systray_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
static void
-systray_plugin_box_expose_event_icon (GtkWidget *child,
- gpointer user_data)
+systray_plugin_box_draw_icon (GtkWidget *child,
+ gpointer user_data)
{
cairo_t *cr = user_data;
- GtkAllocation *alloc;
+ GtkAllocation alloc;
if (systray_socket_is_composited (XFCE_SYSTRAY_SOCKET (child)))
{
- alloc = &child->allocation;
+ gtk_widget_get_allocation (child, &alloc);
/* skip hidden (see offscreen in box widget) icons */
- if (alloc->x > -1 && alloc->y > -1)
+ if (alloc.x > -1 && alloc.y > -1)
{
- gdk_cairo_set_source_pixmap (cr, gtk_widget_get_window (child),
- alloc->x, alloc->y);
+ // FIXME
+ //gdk_cairo_set_source_pixmap (cr, gtk_widget_get_window (child),
+ // alloc.x, alloc.y);
cairo_paint (cr);
}
}
@@ -618,27 +623,18 @@ systray_plugin_box_expose_event_icon (GtkWidget *child,
static void
-systray_plugin_box_expose_event (GtkWidget *box,
- GdkEventExpose *event)
+systray_plugin_box_draw (GtkWidget *box,
+ cairo_t *cr)
{
- cairo_t *cr;
+ panel_return_if_fail (cr != NULL);
if (!gtk_widget_is_composited (box))
return;
- cr = gdk_cairo_create (gtk_widget_get_window (box));
- if (G_LIKELY (cr != NULL))
- {
- gdk_cairo_rectangle (cr, &event->area);
- cairo_clip (cr);
-
- /* separately draw all the composed tray icons after gtk
- * handled the expose event */
- gtk_container_foreach (GTK_CONTAINER (box),
- systray_plugin_box_expose_event_icon, cr);
-
- cairo_destroy (cr);
- }
+ /* separately draw all the composed tray icons after gtk
+ * handled the draw event */
+ gtk_container_foreach (GTK_CONTAINER (box),
+ systray_plugin_box_draw_icon, cr);
}
More information about the Xfce4-commits
mailing list