aboutsummaryrefslogtreecommitdiff
path: root/libtopmenu-client
diff options
context:
space:
mode:
Diffstat (limited to 'libtopmenu-client')
-rw-r--r--libtopmenu-client/Makefile.am8
-rw-r--r--libtopmenu-client/topmenu-appmenubar.h2
-rw-r--r--libtopmenu-client/topmenu-client.c48
-rw-r--r--libtopmenu-client/topmenu-client.h1
-rw-r--r--libtopmenu-client/topmenu-monitor.c3
-rw-r--r--libtopmenu-client/topmenu-monitor.h4
6 files changed, 54 insertions, 12 deletions
diff --git a/libtopmenu-client/Makefile.am b/libtopmenu-client/Makefile.am
index f4f8b6f..2f2fc31 100644
--- a/libtopmenu-client/Makefile.am
+++ b/libtopmenu-client/Makefile.am
@@ -4,8 +4,8 @@ lib_LTLIBRARIES = libtopmenu-client-gtk3.la
libtopmenu_client_gtk3_la_SOURCES = topmenu-client.c topmenu-client.h \
topmenu-monitor.c topmenu-monitor.h \
topmenu-appmenubar.c topmenu-appmenubar.h
-libtopmenu_client_gtk3_la_CPPFLAGS = $(GTK_CFLAGS) -DG_LOG_DOMAIN=\"topmenu-client\"
-libtopmenu_client_gtk3_la_LIBADD = $(GTK_LIBS)
+libtopmenu_client_gtk3_la_CPPFLAGS = $(GTK_CFLAGS) -I../libtopmenu-common -DG_LOG_DOMAIN=\"topmenu-client\"
+libtopmenu_client_gtk3_la_LIBADD = $(GTK_LIBS) ../libtopmenu-common/libtopmenu-common-gtk3.la
else
@@ -13,8 +13,8 @@ lib_LTLIBRARIES = libtopmenu-client-gtk2.la
libtopmenu_client_gtk2_la_SOURCES = topmenu-client.c topmenu-client.h \
topmenu-monitor.c topmenu-monitor.h \
topmenu-appmenubar.c topmenu-appmenubar.h
-libtopmenu_client_gtk2_la_CPPFLAGS = $(GTK_CFLAGS) -DG_LOG_DOMAIN=\"topmenu-client\"
-libtopmenu_client_gtk2_la_LIBADD = $(GTK_LIBS)
+libtopmenu_client_gtk2_la_CPPFLAGS = $(GTK_CFLAGS) -I../libtopmenu-common -DG_LOG_DOMAIN=\"topmenu-client\"
+libtopmenu_client_gtk2_la_LIBADD = $(GTK_LIBS) ../libtopmenu-common/libtopmenu-common-gtk2.la
endif
diff --git a/libtopmenu-client/topmenu-appmenubar.h b/libtopmenu-client/topmenu-appmenubar.h
index 012d82f..575ac6e 100644
--- a/libtopmenu-client/topmenu-appmenubar.h
+++ b/libtopmenu-client/topmenu-appmenubar.h
@@ -45,7 +45,7 @@ struct _TopMenuAppMenuBarClass
GtkMenuBarClass parent_class;
};
-GType topmenu_app_menu_bar_get_type(void);
+GType topmenu_app_menu_bar_get_type(void) G_GNUC_CONST;
TopMenuAppMenuBar *topmenu_app_menu_bar_new(void);
diff --git a/libtopmenu-client/topmenu-client.c b/libtopmenu-client/topmenu-client.c
index e62104e..ae9eac3 100644
--- a/libtopmenu-client/topmenu-client.c
+++ b/libtopmenu-client/topmenu-client.c
@@ -28,6 +28,10 @@
#include "topmenu-client.h"
+static G_DEFINE_QUARK(topmenu-plug, plug)
+static G_DEFINE_QUARK(topmenu-background, background)
+static Atom atom_change_background = None;
+
static gboolean handle_plug_delete(GtkPlug *plug, GdkEvent *event, GdkWindow *window)
{
return TRUE; // Prevent deletion of plug window
@@ -85,14 +89,39 @@ static gboolean handle_widget_button_event(GtkWidget *widget, GdkEvent *event, G
return FALSE;
}
+static GdkFilterReturn handle_plug_window_event(GdkXEvent *xevent, GdkEvent *event, gpointer data)
+{
+ GdkWindow *window = GDK_WINDOW(data);
+ if (((XEvent*)xevent)->type == ClientMessage) {
+ XClientMessageEvent *msg = (XClientMessageEvent*) xevent;
+ if (msg->message_type == atom_change_background) {
+ g_debug("received change background message");
+ TopMenuBackground *bg = g_object_get_qdata(G_OBJECT(window), background_quark());
+ g_return_val_if_fail(bg, GDK_FILTER_REMOVE);
+
+ topmenu_background_set_from_client_message(bg, msg);
+
+ return GDK_FILTER_REMOVE;
+ }
+ }
+
+ return GDK_FILTER_CONTINUE;
+}
+
void topmenu_client_connect_window_widget(GdkWindow *window, GtkWidget *widget)
{
Display *display = GDK_WINDOW_XDISPLAY(window);
- if (g_object_get_data(G_OBJECT(window), OBJECT_DATA_KEY_PLUG)) {
+ // Disconnect any pre-existing widget
+ if (g_object_get_qdata(G_OBJECT(window), plug_quark())) {
topmenu_client_disconnect_window(window);
}
+ // Initialize atoms now
+ if (atom_change_background == None) {
+ atom_change_background = XInternAtom(display, ATOM_TOPMENU_BACKGROUND_CHANGE, False);
+ }
+
Window xwin = GDK_WINDOW_XID(window);
GtkPlug *plug = GTK_PLUG(gtk_plug_new(0));
gtk_container_add(GTK_CONTAINER(plug), widget);
@@ -102,6 +131,9 @@ void topmenu_client_connect_window_widget(GdkWindow *window, GtkWidget *widget)
G_CALLBACK(handle_widget_button_event), plug, 0);
g_signal_connect_object(widget, "button-release-event",
G_CALLBACK(handle_widget_button_event), plug, 0);
+ gtk_widget_realize(GTK_WIDGET(plug));
+ gdk_window_add_filter(gtk_widget_get_window(GTK_WIDGET(plug)),
+ handle_plug_window_event, window);
gtk_widget_show(GTK_WIDGET(plug));
Window plug_xwin = gtk_plug_get_id(plug);
@@ -112,17 +144,27 @@ void topmenu_client_connect_window_widget(GdkWindow *window, GtkWidget *widget)
XA_WINDOW, 32, PropModeReplace,
(unsigned char*)&plug_xwin, 1);
- g_object_set_data_full(G_OBJECT(window), OBJECT_DATA_KEY_PLUG, plug,
+ g_object_set_qdata_full(G_OBJECT(window), plug_quark(), plug,
(GDestroyNotify) &gtk_widget_destroy);
+
+ // Connect the background
+ TopMenuBackground *bg = topmenu_background_new();
+ topmenu_background_connect(bg, widget);
+
+ // Destroy the background when the window is destroyed
+ g_object_set_qdata_full(G_OBJECT(window), background_quark(),
+ bg, g_object_unref);
}
void topmenu_client_disconnect_window(GdkWindow *window)
{
Display *display = GDK_WINDOW_XDISPLAY(window);
- gpointer window_data = g_object_steal_data(G_OBJECT(window), OBJECT_DATA_KEY_PLUG);
+ gpointer window_data = g_object_steal_qdata(G_OBJECT(window), plug_quark());
g_return_if_fail(window_data);
+ g_object_set_qdata(G_OBJECT(window), background_quark(), NULL);
+
Window xwin = GDK_WINDOW_XID(window);
GtkPlug *plug = GTK_PLUG(window_data);
diff --git a/libtopmenu-client/topmenu-client.h b/libtopmenu-client/topmenu-client.h
index d9af99c..0fad7d0 100644
--- a/libtopmenu-client/topmenu-client.h
+++ b/libtopmenu-client/topmenu-client.h
@@ -21,6 +21,7 @@
#define _TOPMENU_CLIENT_H_
#include <gtk/gtk.h>
+#include <topmenu-background.h>
G_BEGIN_DECLS
diff --git a/libtopmenu-client/topmenu-monitor.c b/libtopmenu-client/topmenu-monitor.c
index c67e3cd..b03502e 100644
--- a/libtopmenu-client/topmenu-monitor.c
+++ b/libtopmenu-client/topmenu-monitor.c
@@ -53,10 +53,10 @@ static void handle_clipboard_owner_change(GtkClipboard *clipboard, GdkEvent *eve
static GdkFilterReturn handle_cur_server_event(GdkXEvent *xevent, GdkEvent *event, gpointer data)
{
+ TopMenuMonitor *self = TOPMENU_MONITOR(data);
XEvent *e = (XEvent*)xevent;
if (e->type == DestroyNotify) {
g_debug("Current server has been destroyed");
- TopMenuMonitor *self = TOPMENU_MONITOR(data);
if (self->priv->cur_server &&
GDK_WINDOW_XID(self->priv->cur_server) == e->xdestroywindow.window) {
topmenu_monitor_update(self);
@@ -155,7 +155,6 @@ static void topmenu_monitor_class_init(TopMenuMonitorClass *klass)
static void topmenu_monitor_init(TopMenuMonitor *self)
{
self->priv = TOPMENU_MONITOR_GET_PRIVATE(self);
- self->available = FALSE;
self->priv->atom_selection = gdk_atom_intern_static_string(ATOM_TOPMENU_SERVER_SELECTION);
self->priv->selection = gtk_clipboard_get(self->priv->atom_selection);
diff --git a/libtopmenu-client/topmenu-monitor.h b/libtopmenu-client/topmenu-monitor.h
index 1128d6d..12ff511 100644
--- a/libtopmenu-client/topmenu-monitor.h
+++ b/libtopmenu-client/topmenu-monitor.h
@@ -47,11 +47,11 @@ struct _TopMenuMonitorClass
GObjectClass parent_class;
};
-GType topmenu_monitor_get_type(void);
+GType topmenu_monitor_get_type(void) G_GNUC_CONST;
TopMenuMonitor * topmenu_monitor_get_instance(void);
-gboolean topmenu_monitor_is_topmenu_available(TopMenuMonitor * self);
+gboolean topmenu_monitor_is_topmenu_available(TopMenuMonitor *self);
G_END_DECLS