GTK+2 panel 

GTK+2 panel Git Source Tree

Root/netwm.c

1#include "netwm.h"
2
3unsigned long
4gpwm_window_get_property (Window window,
5 const gchar *property,
6 Atom a_type,
7 gpointer *data)
8{
9 Atom a_type_return;
10 int format_return;
11 unsigned long n_items;
12 unsigned long after_return;
13
14 g_return_val_if_fail (window != None, 0UL);
15 g_return_val_if_fail (property != NULL, 0UL);
16 g_return_val_if_fail (data != NULL, 0UL);
17
18 if (XGetWindowProperty (GPWM_DISPLAY, window, gpwm_intern_atom (property),
19 0, G_MAXLONG-1, FALSE, a_type,
20 &a_type_return, &format_return,
21 &n_items, &after_return, (unsigned char **) data) != Success)
22 return 0UL;
23
24 return n_items;
25}
26
27gboolean
28gpwm_window_change_property32 (Window window,
29 const gchar *property,
30 Atom a_type,
31 gint32 *data,
32 int n_data)
33{
34 g_return_val_if_fail (window != None, FALSE);
35 g_return_val_if_fail (property != NULL, FALSE);
36 g_return_val_if_fail (data != NULL, FALSE);
37
38 if (XChangeProperty (GPWM_DISPLAY, window, gpwm_intern_atom (property),
39 a_type, 32, PropModeReplace,
40 (unsigned char *) data, n_data) != Success)
41 return FALSE;
42
43 return TRUE;
44}
45
46int
47gpwm_window_get_desktop (Window window)
48{
49 gpointer data;
50 int desktop;
51
52 if (!gpwm_window_get_property (window, "_NET_WM_DESKTOP", XA_CARDINAL, &data))
53 return 0;
54
55 desktop = * (int *) data;
56 XFree (data);
57 return desktop;
58}
59
60GdkWindowTypeHint
61gpwm_window_get_type (Window window)
62{
63 gpointer data;
64 unsigned long atoms;
65 Atom *atom;
66 GdkWindowTypeHint state;
67
68 atoms = gpwm_window_get_property (window, "_NET_WM_WINDOW_TYPE", XA_ATOM, &data);
69 if (!atoms)
70 return 0;
71
72 state = 0;
73
74 for (atom = (Atom *) data; atoms --; ++ atom)
75 if (*atom == gpwm_intern_atom ("_NET_WM_WINDOW_TYPE_NORMAL"))
76 state |= GDK_WINDOW_TYPE_HINT_NORMAL;
77 else if (*atom == gpwm_intern_atom ("_NET_WM_WINDOW_TYPE_DIALOG"))
78 state |= GDK_WINDOW_TYPE_HINT_DIALOG;
79 else if (*atom == gpwm_intern_atom ("_NET_WM_WINDOW_TYPE_MENU"))
80 state |= GDK_WINDOW_TYPE_HINT_MENU;
81 else if (*atom == gpwm_intern_atom ("_NET_WM_WINDOW_TYPE_TOOLBAR"))
82 state |= GDK_WINDOW_TYPE_HINT_TOOLBAR;
83 else if (*atom == gpwm_intern_atom ("_NET_WM_WINDOW_TYPE_SPLASHSCREEN"))
84 state |= GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
85 else if (*atom == gpwm_intern_atom ("_NET_WM_WINDOW_TYPE_UTILITY"))
86 state |= GDK_WINDOW_TYPE_HINT_UTILITY;
87 else if (*atom == gpwm_intern_atom ("_NET_WM_WINDOW_TYPE_DOCK"))
88 state |= GDK_WINDOW_TYPE_HINT_DOCK;
89 else if (*atom == gpwm_intern_atom ("_NET_WM_WINDOW_TYPE_DESKTOP"))
90 state |= GDK_WINDOW_TYPE_HINT_DESKTOP;
91
92 XFree (data);
93 return state;
94}
95
96int
97gpwm_get_current_desktop (void)
98{
99 gpointer data;
100 int desktop;
101
102 if (!gpwm_get_property ("_NET_CURRENT_DESKTOP", XA_CARDINAL, &data))
103 return 0;
104
105 desktop = * (int *) data;
106 XFree (data);
107 return desktop;
108}
109
110gboolean
111gpwm_is_supported (const gchar *feature)
112{
113 gpointer data;
114 unsigned long atoms;
115 Atom *atom;
116 Atom a_feature;
117 gboolean supported;
118
119 atoms = gpwm_get_property ("_NET_SUPPORTED", XA_ATOM, &data);
120 if (!atoms)
121 return FALSE;
122
123 a_feature = gpwm_intern_atom (feature);
124 supported = FALSE;
125
126 for (atom = (Atom *) data; atoms --; ++ atom)
127 if (*atom == a_feature)
128 {
129supported = TRUE;
130break;
131 }
132
133 XFree (data);
134 return supported;
135}

Archive Download this file

Branches

Tags