[Xfce4-commits] [panel-plugins/xfce4-clipman-plugin] 27/28: Port GdkEventClient to XSendEvent
noreply at xfce.org
noreply at xfce.org
Thu May 19 20:06:29 CEST 2016
This is an automated email from the git hooks/post-receive script.
ochosi pushed a commit to branch master
in repository panel-plugins/xfce4-clipman-plugin.
commit 37c73db54ff8dd4c48b15d2111e4b8be5b49ca15
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Wed May 18 23:13:47 2016 +0200
Port GdkEventClient to XSendEvent
---
panel-plugin/plugin.c | 57 +++++++++++++++++++++++---------------
panel-plugin/xfce4-popup-clipman.c | 28 ++++++++++++-------
2 files changed, 53 insertions(+), 32 deletions(-)
diff --git a/panel-plugin/plugin.c b/panel-plugin/plugin.c
index 1b9f415..05ae5a0 100644
--- a/panel-plugin/plugin.c
+++ b/panel-plugin/plugin.c
@@ -43,8 +43,9 @@
*/
static gboolean my_plugin_set_popup_selection (MyPlugin *plugin);
-static gboolean cb_popup_message_received (MyPlugin *plugin,
- GdkEvent *ev, gpointer user_data);
+static GdkFilterReturn event_filter_popup_menu (GdkXEvent *xevent,
+ GdkEvent *event,
+ MyPlugin *plugin);
static gboolean xfce_popup_grab_available (GdkWindow *win,
guint32 timestamp);
@@ -132,7 +133,6 @@ plugin_register (void)
G_CALLBACK (plugin_save), plugin);
g_signal_connect_swapped (plugin->history, "clear",
G_CALLBACK (plugin_save), plugin);
-
/* Set the selection for the popup command */
my_plugin_set_popup_selection (plugin);
@@ -280,6 +280,7 @@ plugin_free (MyPlugin *plugin)
gsd_clipboard_manager_stop (plugin->daemon);
g_object_unref (plugin->daemon);
}
+ gdk_window_remove_filter (gtk_widget_get_window(plugin->menu), (GdkFilterFunc) event_filter_popup_menu, plugin);
gtk_widget_destroy (plugin->menu);
g_object_unref (plugin->channel);
g_object_unref (plugin->actions);
@@ -383,6 +384,7 @@ my_plugin_set_popup_selection (MyPlugin *plugin)
GtkWidget *win;
Window id;
Display *display;
+ GdkWindow *window;
win = gtk_invisible_new ();
gtk_widget_realize (win);
@@ -393,7 +395,6 @@ my_plugin_set_popup_selection (MyPlugin *plugin)
selection_name = g_strdup_printf (XFCE_CLIPMAN_SELECTION"%d",
gdk_screen_get_number (gscreen));
selection_atom = XInternAtom (display, selection_name, FALSE);
-
g_free(selection_name);
if (XGetSelectionOwner (display, selection_atom))
@@ -405,39 +406,51 @@ my_plugin_set_popup_selection (MyPlugin *plugin)
XSelectInput (display, id, PropertyChangeMask);
XSetSelectionOwner (display, selection_atom, id, GDK_CURRENT_TIME);
- g_signal_connect_swapped (win, "event",
- G_CALLBACK (cb_popup_message_received), plugin);
+ window = gtk_widget_get_window (win);
+ gdk_window_add_filter (window, (GdkFilterFunc) event_filter_popup_menu, plugin);
return TRUE;
}
-static gboolean
-cb_popup_message_received (MyPlugin *plugin,
- GdkEvent *ev, gpointer user_data)
+static GdkFilterReturn
+event_filter_popup_menu (GdkXEvent *xevent, GdkEvent *event, MyPlugin *plugin)
{
- {
+ XClientMessageEvent *evt;
+ GdkScreen *screen;
+ GdkWindow *root;
+ Atom message_type;
+ evt = (XClientMessageEvent *)xevent;
+
+ if (((XEvent *)xevent)->type != ClientMessage)
+ return GDK_FILTER_CONTINUE;
+
+ message_type = XInternAtom (gdk_x11_get_default_xdisplay (), "STRING", FALSE);
+ if (evt->message_type != message_type)
+ return GDK_FILTER_CONTINUE;
+
/* Copy workaround from xfdesktop to handle the awkward case where binding
* a keyboard shortcut to the popup command doesn't always work out... */
#ifdef PANEL_PLUGIN
- GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (plugin->button));
+ screen = gtk_widget_get_screen (GTK_WIDGET (plugin->button));
#elif defined (STATUS_ICON)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- GdkScreen *screen = gtk_status_icon_get_screen (plugin->status_icon);
+ screen = gtk_status_icon_get_screen (plugin->status_icon);
G_GNUC_END_IGNORE_DEPRECATIONS
#endif
- GdkWindow *root = gdk_screen_get_root_window (screen);
+ root = gdk_screen_get_root_window (screen);
+
if (!xfce_popup_grab_available (root, GDK_CURRENT_TIME))
{
g_critical ("Unable to get keyboard/mouse grab.");
return FALSE;
}
- }
- //if (G_LIKELY (ev->data_format == 8 && *(ev->data.b) != '\0'))
- //{
- //if (!g_ascii_strcasecmp (XFCE_CLIPMAN_MESSAGE, ev->data.b))
- //{
- //DBG ("Message received: %s", ev->data.b);
+ if (G_LIKELY (evt->format == 8) && (*(evt->data.b) != '\0'))
+ {
+
+ if (!g_ascii_strcasecmp (XFCE_CLIPMAN_MESSAGE, evt->data.b))
+ {
+ DBG ("Message received: %s", evt->data.b);
if (xfconf_channel_get_bool (plugin->channel, "/tweaks/popup-at-pointer", FALSE))
{
@@ -450,10 +463,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
}
return TRUE;
- //}
- //}
+ }
+ }
- //return FALSE;
+ return FALSE;
}
/* Code taken from xfwm4/src/menu.c:grab_available(). This should fix the case
diff --git a/panel-plugin/xfce4-popup-clipman.c b/panel-plugin/xfce4-popup-clipman.c
index 1698624..afeb96d 100644
--- a/panel-plugin/xfce4-popup-clipman.c
+++ b/panel-plugin/xfce4-popup-clipman.c
@@ -53,24 +53,32 @@ clipman_plugin_check_is_running (GtkWidget *widget,
gint
main (gint argc, gchar *argv[])
{
- GtkWidget *win;
+ XEvent event;
+ GtkWidget *win;
+ GdkWindow *window;
Window id;
+ Display *display;
gtk_init (&argc, &argv);
win = gtk_invisible_new ();
gtk_widget_realize (win);
- //gev.type = GDK_CLIENT_EVENT;
- //gev.window = gtk_widget_get_window (win);
- //gev.send_event = TRUE;
- //gev.message_type = gdk_atom_intern ("STRING", FALSE);
- //gev.data_format = 8;
- //g_snprintf (gev.data.b, sizeof (gev.data.b), XFCE_CLIPMAN_MESSAGE);
+ window = gtk_widget_get_window (GTK_WIDGET (win));
+ display = gdk_x11_display_get_xdisplay (gdk_window_get_display (window));
+ event.xclient.type = ClientMessage;
+ event.xclient.message_type = XInternAtom (display, "STRING", False);
+ event.xclient.format = 8;
+ g_snprintf (event.xclient.data.b, sizeof (event.xclient.data.b), XFCE_CLIPMAN_MESSAGE);
- if (clipman_plugin_check_is_running (win, &id))
- g_warning ("Fixme...");
- //gdk_event_send_client_message ((GdkEvent *)&gev, (GdkNativeWindow)id);
+ if (clipman_plugin_check_is_running (win, &id)) {
+ event.xclient.window = id;
+ XSendEvent (display,
+ (Window) id,
+ False,
+ NoEventMask,
+ &event);
+ }
else
g_warning ("Can't find the xfce4-clipman-plugin.\n");
gdk_flush ();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list