[gnome-panel/wip/showdesktop] ShowDesktop Applet: Replace ToggleButton
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/showdesktop] ShowDesktop Applet: Replace ToggleButton
- Date: Fri, 27 Mar 2015 19:39:14 +0000 (UTC)
commit 16cd57ee141539f3c3998b32cfa3d2ae375b9650
Author: Sebastian Geiger <sbastig gmx net>
Date: Fri Mar 27 20:36:30 2015 +0100
ShowDesktop Applet: Replace ToggleButton
* Buttons are always drawn with background even
if the transparency is activated on the panel,
by using an EventBox we can have fix this issue
and have a transparent show desktop button.
applets/wncklet/showdesktop.c | 140 ++++++++++++++++++++---------------------
1 files changed, 69 insertions(+), 71 deletions(-)
---
diff --git a/applets/wncklet/showdesktop.c b/applets/wncklet/showdesktop.c
index 1790059..222375a 100644
--- a/applets/wncklet/showdesktop.c
+++ b/applets/wncklet/showdesktop.c
@@ -42,7 +42,7 @@
typedef struct {
/* widgets */
GtkWidget *applet;
- GtkWidget *button;
+ GtkWidget *box;
GtkWidget *image;
GtkOrientation orient;
@@ -51,19 +51,20 @@ typedef struct {
WnckScreen *wnck_screen;
guint showing_desktop : 1;
- guint button_activate;
+ guint box_activate;
GtkIconTheme *icon_theme;
} ShowDesktopData;
static void update_icon (ShowDesktopData *sdd);
-static void update_button_state (ShowDesktopData *sdd);
-static void update_button_display (ShowDesktopData *sdd);
+static void update_box_state (ShowDesktopData *sdd);
+static void update_box_display (ShowDesktopData *sdd);
static void theme_changed_callback (GtkIconTheme *icon_theme,
ShowDesktopData *sdd);
-static void button_toggled_callback (GtkWidget *button,
+static gboolean box_button_release_callback (GtkWidget *box,
+ GdkEvent *event,
ShowDesktopData *sdd);
static void show_desktop_changed_callback (WnckScreen *screen,
ShowDesktopData *sdd);
@@ -100,7 +101,7 @@ applet_change_orient (PanelApplet *applet,
/* this is when the panel size changes */
static void
-button_size_allocated (GtkWidget *button,
+box_size_allocated (GtkWidget *box,
GtkAllocation *allocation,
ShowDesktopData *sdd)
{
@@ -140,8 +141,8 @@ update_icon (ShowDesktopData *sdd)
if (!sdd->icon_theme)
return;
- state = gtk_widget_get_state_flags (sdd->button);
- context = gtk_widget_get_style_context (sdd->button);
+ state = gtk_widget_get_state_flags (sdd->box);
+ context = gtk_widget_get_style_context (sdd->box);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get_style (context,
"focus-line-width", &focus_width,
@@ -215,56 +216,52 @@ update_icon (ShowDesktopData *sdd)
g_object_unref (icon);
}
-/* This updates things that should be consistent with the button's appearance,
- * and update_button_state updates the button appearance itself
+/* This updates things that should be consistent with the box's appearance,
+ * and update_box_state updates the box appearance itself
*/
static void
-update_button_display (ShowDesktopData *sdd)
+update_box_display (ShowDesktopData *sdd)
{
const char *tip;
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (sdd->button))) {
+ if (sdd->showing_desktop) {
tip = _("Click here to restore hidden windows.");
} else {
tip = _("Click here to hide all windows and show the desktop.");
}
- gtk_widget_set_tooltip_text (sdd->button, tip);
+ gtk_widget_set_tooltip_text (sdd->box, tip);
}
static void
-update_button_state (ShowDesktopData *sdd)
+update_box_state (ShowDesktopData *sdd)
{
if (sdd->showing_desktop) {
- g_signal_handlers_block_by_func (G_OBJECT (sdd->button),
- G_CALLBACK (button_toggled_callback),
+ g_signal_handlers_block_by_func (G_OBJECT (sdd->box),
+ G_CALLBACK (box_button_release_callback),
sdd);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sdd->button),
- TRUE);
- g_signal_handlers_unblock_by_func (G_OBJECT (sdd->button),
- G_CALLBACK (button_toggled_callback),
+ g_signal_handlers_unblock_by_func (G_OBJECT (sdd->box),
+ G_CALLBACK (box_button_release_callback),
sdd);
} else {
- g_signal_handlers_block_by_func (G_OBJECT (sdd->button),
- G_CALLBACK (button_toggled_callback),
+ g_signal_handlers_block_by_func (G_OBJECT (sdd->box),
+ G_CALLBACK (box_button_release_callback),
sdd);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sdd->button),
- FALSE);
- g_signal_handlers_unblock_by_func (G_OBJECT (sdd->button),
- G_CALLBACK (button_toggled_callback),
+ g_signal_handlers_unblock_by_func (G_OBJECT (sdd->box),
+ G_CALLBACK (box_button_release_callback),
sdd);
}
- update_button_display (sdd);
+ update_box_display (sdd);
}
static void
applet_destroyed (GtkWidget *applet,
ShowDesktopData *sdd)
{
- if (sdd->button_activate != 0) {
- g_source_remove (sdd->button_activate);
- sdd->button_activate = 0;
+ if (sdd->box_activate != 0) {
+ g_source_remove (sdd->box_activate);
+ sdd->box_activate = 0;
}
if (sdd->wnck_screen != NULL) {
@@ -296,31 +293,31 @@ do_not_eat_button_press (GtkWidget *widget,
}
static gboolean
-button_motion_timeout (gpointer data)
+box_motion_timeout (gpointer data)
{
ShowDesktopData *sdd = (ShowDesktopData*) data;
- sdd->button_activate = 0;
+ sdd->box_activate = 0;
- g_signal_emit_by_name (G_OBJECT (sdd->button), "clicked", sdd);
+ g_signal_emit_by_name (G_OBJECT (sdd->box), "clicked", sdd);
return FALSE;
}
static void
-button_drag_leave (GtkWidget *widget,
+box_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time,
ShowDesktopData *sdd)
{
- if (sdd->button_activate != 0) {
- g_source_remove (sdd->button_activate);
- sdd->button_activate = 0;
+ if (sdd->box_activate != 0) {
+ g_source_remove (sdd->box_activate);
+ sdd->box_activate = 0;
}
}
static gboolean
-button_drag_motion (GtkWidget *widget,
+box_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
@@ -328,9 +325,9 @@ button_drag_motion (GtkWidget *widget,
ShowDesktopData *sdd)
{
- if (sdd->button_activate == 0)
- sdd->button_activate = g_timeout_add_seconds (TIMEOUT_ACTIVATE_SECONDS,
- button_motion_timeout,
+ if (sdd->box_activate == 0)
+ sdd->box_activate = g_timeout_add_seconds (TIMEOUT_ACTIVATE_SECONDS,
+ box_motion_timeout,
sdd);
gdk_drag_status (context, 0, time);
@@ -416,36 +413,36 @@ show_desktop_applet_fill (PanelApplet *applet)
g_signal_connect (G_OBJECT (sdd->applet), "realize",
G_CALLBACK (show_desktop_applet_realized), sdd);
- sdd->button = gtk_toggle_button_new ();
+ sdd->box = gtk_event_box_new();
- gtk_widget_set_name (sdd->button, "showdesktop-button");
+ gtk_widget_set_name (sdd->box, "showdesktop-box");
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
- "#showdesktop-button {\n"
+ "#showdesktop-box {\n"
" -GtkWidget-focus-line-width: 0px;\n"
" -GtkWidget-focus-padding: 0px;\n"
"}",
-1, NULL);
- gtk_style_context_add_provider (gtk_widget_get_style_context (sdd->button),
+ gtk_style_context_add_provider (gtk_widget_get_style_context (sdd->box),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
- atk_obj = gtk_widget_get_accessible (sdd->button);
+ atk_obj = gtk_widget_get_accessible (sdd->box);
atk_object_set_name (atk_obj, _("Show Desktop Button"));
- g_signal_connect (G_OBJECT (sdd->button), "button_press_event",
+ g_signal_connect (G_OBJECT (sdd->box), "button_press_event",
G_CALLBACK (do_not_eat_button_press), NULL);
- g_signal_connect (G_OBJECT (sdd->button), "toggled",
- G_CALLBACK (button_toggled_callback), sdd);
+ g_signal_connect (G_OBJECT (sdd->box), "button-release-event",
+ G_CALLBACK (box_button_release_callback), sdd);
- gtk_container_set_border_width (GTK_CONTAINER (sdd->button), 0);
- gtk_container_add (GTK_CONTAINER (sdd->button), sdd->image);
- gtk_container_add (GTK_CONTAINER (sdd->applet), sdd->button);
+ gtk_container_set_border_width (GTK_CONTAINER (sdd->box), 0);
+ gtk_container_add (GTK_CONTAINER (sdd->box), sdd->image);
+ gtk_container_add (GTK_CONTAINER (sdd->applet), sdd->box);
- g_signal_connect (G_OBJECT (sdd->button),
+ g_signal_connect (G_OBJECT (sdd->box),
"size_allocate",
- G_CALLBACK (button_size_allocated),
+ G_CALLBACK (box_size_allocated),
sdd);
/* FIXME: Update this comment. */
@@ -462,13 +459,13 @@ show_desktop_applet_fill (PanelApplet *applet)
G_CALLBACK (applet_destroyed),
sdd);
- gtk_drag_dest_set (GTK_WIDGET(sdd->button), 0, NULL, 0, 0);
+ gtk_drag_dest_set (GTK_WIDGET(sdd->box), 0, NULL, 0, 0);
- g_signal_connect (G_OBJECT(sdd->button), "drag_motion",
- G_CALLBACK (button_drag_motion),
+ g_signal_connect (G_OBJECT(sdd->box), "drag_motion",
+ G_CALLBACK (box_drag_motion),
sdd);
- g_signal_connect (G_OBJECT(sdd->button), "drag_leave",
- G_CALLBACK (button_drag_leave),
+ g_signal_connect (G_OBJECT(sdd->box), "drag_leave",
+ G_CALLBACK (box_drag_leave),
sdd);
gtk_widget_show_all (sdd->applet);
@@ -476,21 +473,22 @@ show_desktop_applet_fill (PanelApplet *applet)
return TRUE;
}
-static void
-button_toggled_callback (GtkWidget *button,
- ShowDesktopData *sdd)
+static gboolean
+box_button_release_callback (GtkWidget *box,
+ GdkEvent *event,
+ ShowDesktopData *sdd)
{
- if (!gdk_x11_screen_supports_net_wm_hint (gtk_widget_get_screen (button),
+ if (!gdk_x11_screen_supports_net_wm_hint (gtk_widget_get_screen (box),
gdk_atom_intern ("_NET_SHOWING_DESKTOP", FALSE))) {
static GtkWidget *dialog = NULL;
if (dialog &&
- gtk_widget_get_screen (dialog) != gtk_widget_get_screen (button))
+ gtk_widget_get_screen (dialog) != gtk_widget_get_screen (box))
gtk_widget_destroy (dialog);
if (dialog) {
gtk_window_present (GTK_WINDOW (dialog));
- return;
+ return GDK_EVENT_STOP;
}
dialog = gtk_message_dialog_new (NULL,
@@ -508,17 +506,17 @@ button_toggled_callback (GtkWidget *button,
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_window_set_screen (GTK_WINDOW (dialog),
- gtk_widget_get_screen (button));
+ gtk_widget_get_screen (box));
gtk_widget_show (dialog);
- return;
+ return GDK_EVENT_STOP;
}
if (sdd->wnck_screen != NULL)
wnck_screen_toggle_showing_desktop (sdd->wnck_screen,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(button)));
-
- update_button_display (sdd);
+ !sdd->showing_desktop);
+ update_box_display (sdd);
+ return GDK_EVENT_STOP;
}
static void
@@ -528,5 +526,5 @@ show_desktop_changed_callback (WnckScreen *screen,
if (sdd->wnck_screen != NULL)
sdd->showing_desktop =
wnck_screen_get_showing_desktop (sdd->wnck_screen);
- update_button_state (sdd);
+ update_box_state (sdd);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]