forked from acw/xmonad-log-applet
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.c
167 lines (142 loc) · 3.89 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* main.c
*
* Copyright (c) 2009 Adam Wick
* Copyright (c) 2011-2012 Alexander Kojevnikov
* Copyright (c) 2011 Dan Callaghan
* Copyright (c) 2012 Ari Croock
*
* See LICENSE for licensing information
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <dbus/dbus-glib.h>
#ifdef PANEL_GNOME
#include <panel-applet.h>
#endif
#ifdef PANEL_MATE
#include <mate-panel-applet.h>
#endif
#ifdef PANEL_XFCE4
#include <libxfce4panel/xfce-panel-plugin.h>
#endif
static void signal_handler(DBusGProxy *obj, const char *msg, GtkWidget *widget)
{
gtk_label_set_markup(GTK_LABEL(widget), msg);
}
static void set_up_dbus_transfer(GtkWidget *buf)
{
DBusGConnection *connection;
DBusGProxy *proxy;
GError *error= NULL;
connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if(connection == NULL) {
g_printerr("Failed to open connection: %s\n", error->message);
g_error_free(error);
exit(1);
}
proxy = dbus_g_proxy_new_for_name(
connection, "org.xmonad.Log", "/org/xmonad/Log", "org.xmonad.Log");
error = NULL;
dbus_g_proxy_add_signal(proxy, "Update", G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(
proxy, "Update", (GCallback)signal_handler, buf, NULL);
}
#ifdef PANEL_GNOME
static gboolean xmonad_log_applet_fill(PanelApplet *applet)
#endif
#ifdef PANEL_MATE
static gboolean xmonad_log_applet_fill(MatePanelApplet *applet)
#endif
#ifdef PANEL_XFCE4
static void xmonad_log_applet_fill(GtkContainer *container)
#endif
{
#ifdef PANEL_GNOME
panel_applet_set_flags(
applet,
PANEL_APPLET_EXPAND_MAJOR |
PANEL_APPLET_EXPAND_MINOR |
PANEL_APPLET_HAS_HANDLE);
panel_applet_set_background_widget(applet, GTK_WIDGET(applet));
#endif
#ifdef PANEL_MATE
mate_panel_applet_set_flags(
applet,
MATE_PANEL_APPLET_EXPAND_MAJOR |
MATE_PANEL_APPLET_EXPAND_MINOR |
MATE_PANEL_APPLET_HAS_HANDLE);
mate_panel_applet_set_background_widget(applet, GTK_WIDGET(applet));
#endif
GtkWidget *label = gtk_label_new("Waiting for Xmonad...");
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
set_up_dbus_transfer(label);
#ifndef PANEL_XFCE4
gtk_container_add(GTK_CONTAINER(applet), label);
gtk_widget_show_all(GTK_WIDGET(applet));
return TRUE;
#else
gtk_container_add(container, label);
#endif
}
#ifdef PANEL_GNOME
static gboolean xmonad_log_applet_factory(
PanelApplet *applet, const gchar *iid, gpointer data)
{
gboolean retval = FALSE;
if(!strcmp(iid, "XmonadLogApplet"))
retval = xmonad_log_applet_fill(applet);
if(retval == FALSE) {
printf("Wrong applet!\n");
exit(-1);
}
return retval;
}
#endif
#ifdef PANEL_MATE
static gboolean xmonad_log_applet_factory(
MatePanelApplet *applet, const gchar *iid, gpointer data)
{
gboolean retval = FALSE;
if(!strcmp(iid, "XmonadLogApplet"))
retval = xmonad_log_applet_fill(applet);
if(retval == FALSE) {
printf("Wrong applet!\n");
exit(-1);
}
return retval;
}
#endif
#ifdef PANEL_XFCE4
static void xmonad_log_applet_construct(XfcePanelPlugin *plugin)
{
xmonad_log_applet_fill(GTK_CONTAINER(plugin));
xfce_panel_plugin_set_expand(plugin, TRUE);
gtk_widget_show_all(GTK_WIDGET(plugin));
}
#endif
#ifdef PANEL_GNOME
PANEL_APPLET_OUT_PROCESS_FACTORY(
"XmonadLogAppletFactory",
PANEL_TYPE_APPLET,
#ifdef PANEL_GNOME2
"XmonadLogApplet",
#endif
xmonad_log_applet_factory,
NULL);
#endif
#ifdef PANEL_MATE
MATE_PANEL_APPLET_OUT_PROCESS_FACTORY(
"XmonadLogAppletFactory",
PANEL_TYPE_APPLET,
"XmonadLogApplet",
xmonad_log_applet_factory,
NULL);
#endif
#ifdef PANEL_XFCE4
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(
xmonad_log_applet_construct);
#endif