annotate audacious/hints.c @ 165:d2c091891237 trunk

[svn] sndfile checks
author nenolod
date Sat, 12 Nov 2005 18:02:29 -0800
parents cb178e5ad177
children 5c457dac866a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Based on XMMS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include "hints.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <gtk/gtk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #include "equalizer.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include "mainwin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include "playlistwin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #include <gdk/gdkx.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include <gdk/gdkprivate.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include <X11/Xlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 #include <X11/Xmd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 #include <X11/Xatom.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 /* flags for the window layer */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 typedef enum {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 WIN_LAYER_DESKTOP = 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 WIN_LAYER_BELOW = 2,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 WIN_LAYER_NORMAL = 4,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 WIN_LAYER_ONTOP = 6,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 WIN_LAYER_DOCK = 8,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 WIN_LAYER_ABOVE_DOCK = 10
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 } WinLayer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 #define WIN_STATE_STICKY (1 << 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 #define WIN_HINTS_SKIP_WINLIST (1 << 1) /* not in win list */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 #define WIN_HINTS_SKIP_TASKBAR (1 << 2) /* not on taskbar */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 #define _NET_WM_STATE_REMOVE 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 #define _NET_WM_STATE_ADD 1
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 #define _NET_WM_STATE_TOGGLE 2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 #define _NET_WM_MOVERESIZE_MOVE 8
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 static void (*set_always_func) (GtkWidget *, gboolean) = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 static void (*set_sticky_func) (GtkWidget *, gboolean) = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 static void (*set_skip_winlist_func) (GtkWidget *) = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 static void (*move_resize_func) (GtkWidget *, gint, gint, gboolean) = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 hint_set_skip_winlist(GtkWidget * window)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 if (set_skip_winlist_func)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 set_skip_winlist_func(window);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 hint_set_always(gboolean always)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 if (set_always_func) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 set_always_func(mainwin, always);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 set_always_func(equalizerwin, always);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 set_always_func(playlistwin, always);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 hint_always_on_top_available(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 return !!set_always_func;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 hint_set_sticky(gboolean sticky)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 if (sticky) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 gtk_window_stick(GTK_WINDOW(mainwin));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 gtk_window_stick(GTK_WINDOW(equalizerwin));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 gtk_window_stick(GTK_WINDOW(playlistwin));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 gtk_window_unstick(GTK_WINDOW(mainwin));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 gtk_window_unstick(GTK_WINDOW(equalizerwin));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 gtk_window_unstick(GTK_WINDOW(playlistwin));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 hint_move_resize_available(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 return !!move_resize_func;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 hint_move_resize(GtkWidget * window, gint x, gint y, gboolean move)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 move_resize_func(window, x, y, move);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 net_wm_found(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 Atom r_type, support_check;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 gint r_format, p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 gulong count, bytes_remain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 guchar *prop = NULL, *prop2 = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 gboolean ret = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 gdk_error_trap_push();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 support_check =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 XInternAtom(GDK_DISPLAY(), "_NET_SUPPORTING_WM_CHECK", FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 p = XGetWindowProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), support_check,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 0, 1, False, XA_WINDOW, &r_type, &r_format,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 &count, &bytes_remain, &prop);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 if (p == Success && prop && r_type == XA_WINDOW &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 r_format == 32 && count == 1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 Window n = *(Window *) prop;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 p = XGetWindowProperty(GDK_DISPLAY(), n, support_check, 0, 1,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 False, XA_WINDOW, &r_type, &r_format,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 &count, &bytes_remain, &prop2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 if (p == Success && prop2 && *prop2 == *prop &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 r_type == XA_WINDOW && r_format == 32 && count == 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 ret = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 if (prop)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 XFree(prop);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 if (prop2)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 XFree(prop2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 if (gdk_error_trap_pop())
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 net_wm_set_property(GtkWidget * window, gchar * atom, gboolean state)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 XEvent xev;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 gint set = _NET_WM_STATE_ADD;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 Atom type, property;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 if (state == FALSE)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 set = _NET_WM_STATE_REMOVE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 type = XInternAtom(GDK_DISPLAY(), "_NET_WM_STATE", FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 property = XInternAtom(GDK_DISPLAY(), atom, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 xev.type = ClientMessage;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 xev.xclient.type = ClientMessage;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 xev.xclient.window = GDK_WINDOW_XWINDOW(window->window);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 xev.xclient.message_type = type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 xev.xclient.format = 32;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 xev.xclient.data.l[0] = set;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 xev.xclient.data.l[1] = property;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 xev.xclient.data.l[2] = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 XSendEvent(GDK_DISPLAY(), GDK_ROOT_WINDOW(), False,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 SubstructureNotifyMask, &xev);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 net_wm_set_desktop(GtkWidget * window, gboolean all)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 XEvent xev;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 guint32 current_desktop = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 if (!all) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 gint r_format, p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 gulong count, bytes_remain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 guchar *prop;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 Atom r_type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 Atom current =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 XInternAtom(GDK_DISPLAY(), "_NET_CURRENT_DESKTOP", FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 p = XGetWindowProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), current,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 0, 1, False, XA_CARDINAL, &r_type,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 &r_format, &count, &bytes_remain, &prop);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 if (p == Success && prop && r_type == XA_CARDINAL &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 r_format == 32 && count == 1) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 current_desktop = *(long *) prop;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 XFree(prop);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 current_desktop = 0xffffffff;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 xev.type = ClientMessage;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 xev.xclient.type = ClientMessage;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 xev.xclient.window = GDK_WINDOW_XWINDOW(window->window);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 xev.xclient.message_type =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 XInternAtom(GDK_DISPLAY(), "_NET_WM_DESKTOP", FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 xev.xclient.format = 32;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 xev.xclient.data.l[0] = current_desktop;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 XSendEvent(GDK_DISPLAY(), GDK_ROOT_WINDOW(), False,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 SubstructureNotifyMask, &xev);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 net_wm_set_window_always(GtkWidget * window, gboolean always)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 net_wm_set_property(window, "_NET_WM_STATE_STAYS_ON_TOP", always);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 net_wm_set_window_above(GtkWidget * window, gboolean always)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 net_wm_set_property(window, "_NET_WM_STATE_ABOVE", always);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 net_wm_move_resize(GtkWidget * window, gint x, gint y, gboolean move)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 XEvent xev;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 gint dir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 Atom type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 if (move)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 dir = _NET_WM_MOVERESIZE_MOVE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 gdk_pointer_ungrab(GDK_CURRENT_TIME);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 type = XInternAtom(GDK_DISPLAY(), "_NET_WM_MOVERESIZE", FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 xev.type = ClientMessage;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 xev.xclient.type = ClientMessage;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 xev.xclient.window = GDK_WINDOW_XWINDOW(window->window);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 xev.xclient.message_type = type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 xev.xclient.format = 32;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 xev.xclient.data.l[0] = x;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 xev.xclient.data.l[1] = y;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 xev.xclient.data.l[2] = dir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 xev.xclient.data.l[3] = 1; /* button */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 XSendEvent(GDK_DISPLAY(), GDK_ROOT_WINDOW(), False,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 SubstructureNotifyMask, &xev);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 find_atom(Atom * atoms, gint n, const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 Atom a = XInternAtom(GDK_DISPLAY(), name, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 gint i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 for (i = 0; i < n; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 if (a == atoms[i])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 static gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 get_supported_atoms(Atom ** atoms, gulong * natoms, const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 Atom supported = XInternAtom(GDK_DISPLAY(), name, FALSE), r_type;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 gulong bremain;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 gint r_format, p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 *atoms = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 gdk_error_trap_push();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 p = XGetWindowProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(), supported,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 0, 1000, False, XA_ATOM, &r_type, &r_format,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 natoms, &bremain, (guchar **) atoms);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 if (gdk_error_trap_pop() || p != Success || r_type != XA_ATOM ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 *natoms == 0 || *atoms == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 net_wm_check_features(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 Atom *atoms;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 gulong n_atoms;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 if (!get_supported_atoms(&atoms, &n_atoms, "_NET_SUPPORTED"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 if (find_atom(atoms, n_atoms, "_NET_WM_STATE")) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 if (!set_always_func &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 find_atom(atoms, n_atoms, "_NET_WM_STATE_ABOVE"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 set_always_func = net_wm_set_window_above;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 if (!set_always_func &&
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 find_atom(atoms, n_atoms, "_NET_WM_STATE_STAYS_ON_TOP"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 set_always_func = net_wm_set_window_always;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 if (!set_sticky_func && find_atom(atoms, n_atoms, "_NET_WM_DESKTOP"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 set_sticky_func = net_wm_set_desktop;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 if (find_atom(atoms, n_atoms, "_NET_WM_MOVERESIZE"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 move_resize_func = net_wm_move_resize;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 XFree(atoms);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 check_wm_hints(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 if (net_wm_found()) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 g_message("found NET_WM");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 net_wm_check_features();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 }