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
|
/* $Id$
*
* Copyright (c) 2005 Jasper Huijsmans <jasper@xfce.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <X11/Xlib.h>
#include <gtk/gtk.h>
#include <libxfce4util/libxfce4util.h>
#include "panel-app.h"
#include "panel-app-messages.h"
#ifndef _
#define _(x) x
#endif
#define PANEL_APP_ATOM "XFCE4_PANEL_APP"
/* client messages */
static gboolean
client_event_received (GtkWidget *win,
GdkEventClient *ev)
{
GdkAtom atom = gdk_atom_intern (PANEL_APP_ATOM, FALSE);
if (ev->message_type == atom)
{
switch (ev->data.s[0])
{
case PANEL_APP_CUSTOMIZE:
panel_app_customize ();
break;
case PANEL_APP_SAVE:
panel_app_save ();
break;
case PANEL_APP_RESTART:
panel_app_restart ();
break;
case PANEL_APP_QUIT:
panel_app_quit ();
break;
case PANEL_APP_EXIT:
panel_app_quit_noconfirm ();
break;
case PANEL_APP_ADD:
panel_app_customize_items (NULL);
break;
default:
return FALSE;
}
return TRUE;
}
return FALSE;
}
/* public API */
/**
* panel_app_send
* @message: %PanelAppMesssage
*
* Send a message to a running instance of xfce4-panel.
*
* Return value: %FALSE if no panel instance is running, or %TRUE otherwise.
**/
gboolean
panel_app_send (PanelAppMessage message)
{
Window win;
GdkEventClient gev;
GtkWidget *invisible;
if (panel_app_init () != 1)
{
g_warning ("xfce4-panel is not running");
return FALSE;
}
win = panel_app_get_ipc_window ();
if (win)
{
invisible = gtk_invisible_new ();
gtk_widget_realize (invisible);
gev.type = GDK_CLIENT_EVENT;
gev.window = invisible->window;
gev.send_event = TRUE;
gev.message_type = gdk_atom_intern (PANEL_APP_ATOM, FALSE);
gev.data_format = 16;
gev.data.s[0] = message;
gev.data.s[1] = 0;
gdk_event_send_client_message ((GdkEvent *) & gev,
(GdkNativeWindow) win);
gdk_flush ();
gtk_widget_destroy (invisible);
}
return TRUE;
}
/**
* panel_app_listen
* @ipc_window: #GtkWidget that will receive messages.
*
* Set up listeners for messages to @ipc_window.
**/
void
panel_app_listen (GtkWidget *ipc_window)
{
g_signal_connect (G_OBJECT (ipc_window), "client-event",
G_CALLBACK (client_event_received), NULL);
}
|