]> Dogcows Code - chaz/tint2/blob - src/util/window.c
big change : panel_monitor = all will draw one panel per monitor, panel_size accept...
[chaz/tint2] / src / util / window.c
1 /**************************************************************************
2 *
3 * Tint2 : common windows function
4 *
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
20
21 #include <X11/Xlib.h>
22 #include <X11/Xutil.h>
23 #include <X11/Xatom.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include <Imlib2.h>
29 #include <cairo.h>
30 #include <cairo-xlib.h>
31
32 #include "common.h"
33 #include "window.h"
34 #include "server.h"
35 #include "panel.h"
36
37
38
39 void set_active (Window win)
40 {
41 send_event32 (win, server.atom._NET_ACTIVE_WINDOW, 2, 0);
42 }
43
44
45 void set_desktop (int desktop)
46 {
47 send_event32 (server.root_win, server.atom._NET_CURRENT_DESKTOP, desktop, 0);
48 }
49
50
51 void windows_set_desktop (Window win, int desktop)
52 {
53 send_event32 (win, server.atom._NET_WM_DESKTOP, desktop, 2);
54 }
55
56
57 void set_close (Window win)
58 {
59 send_event32 (win, server.atom._NET_CLOSE_WINDOW, 0, 2);
60 }
61
62
63 void window_toggle_shade (Window win)
64 {
65 send_event32 (win, server.atom._NET_WM_STATE, 2, server.atom._NET_WM_STATE_SHADED);
66 }
67
68
69 int window_is_hidden (Window win)
70 {
71 Window window;
72 Atom *at;
73 int count, i;
74
75 if (XGetTransientForHint(server.dsp, win, &window) != 0) {
76 if (window) {
77 return 1;
78 }
79 }
80
81 at = server_get_property (win, server.atom._NET_WM_STATE, XA_ATOM, &count);
82 for (i = 0; i < count; i++) {
83 if (at[i] == server.atom._NET_WM_STATE_SKIP_PAGER || at[i] == server.atom._NET_WM_STATE_SKIP_TASKBAR) {
84 XFree(at);
85 return 1;
86 }
87 }
88 XFree(at);
89
90 at = server_get_property (win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, &count);
91 for (i = 0; i < count; i++) {
92 if (at[i] == server.atom._NET_WM_WINDOW_TYPE_DOCK || at[i] == server.atom._NET_WM_WINDOW_TYPE_DESKTOP || at[i] == server.atom._NET_WM_WINDOW_TYPE_TOOLBAR || at[i] == server.atom._NET_WM_WINDOW_TYPE_MENU || at[i] == server.atom._NET_WM_WINDOW_TYPE_SPLASH) {
93 XFree(at);
94 return 1;
95 }
96 }
97 XFree(at);
98
99 for (i=0 ; i < nb_panel ; i++) {
100 if (panel1[i].main_win == win)
101 return 1;
102 }
103
104 // specification
105 // Windows with neither _NET_WM_WINDOW_TYPE nor WM_TRANSIENT_FOR set
106 // MUST be taken as top-level window.
107 return 0;
108 }
109
110
111 int window_get_desktop (Window win)
112 {
113 return get_property32(win, server.atom._NET_WM_DESKTOP, XA_CARDINAL);
114 }
115
116
117 int window_get_monitor (Window win)
118 {
119 int i, x, y;
120 Window src;
121
122 XTranslateCoordinates(server.dsp, win, server.root_win, 0, 0, &x, &y, &src);
123 x += 2;
124 y += 2;
125 for (i = 0; i < server.nb_monitor; i++) {
126 if (x >= server.monitor[i].x && x <= (server.monitor[i].x + server.monitor[i].width))
127 if (y >= server.monitor[i].y && y <= (server.monitor[i].y + server.monitor[i].height))
128 break;
129 }
130
131 //printf("window %lx : ecran %d, (%d, %d)\n", win, i, x, y);
132 if (i == server.nb_monitor) return 0;
133 else return i;
134 }
135
136
137 int window_is_iconified (Window win)
138 {
139 return (IconicState == get_property32(win, server.atom.WM_STATE, server.atom.WM_STATE));
140 }
141
142
143 int server_get_number_of_desktop ()
144 {
145 return get_property32(server.root_win, server.atom._NET_NUMBER_OF_DESKTOPS, XA_CARDINAL);
146 }
147
148
149 int server_get_current_desktop ()
150 {
151 return get_property32(server.root_win, server.atom._NET_CURRENT_DESKTOP, XA_CARDINAL);
152 }
153
154
155 Window window_get_active ()
156 {
157 return get_property32(server.root_win, server.atom._NET_ACTIVE_WINDOW, XA_WINDOW);
158 }
159
160
161 int window_is_active (Window win)
162 {
163 return (win == get_property32(server.root_win, server.atom._NET_ACTIVE_WINDOW, XA_WINDOW));
164 }
165
166
167 int get_icon_count (long *data, int num)
168 {
169 int count, pos, w, h;
170
171 count = 0;
172 pos = 0;
173 while (pos < num) {
174 w = data[pos++];
175 h = data[pos++];
176 pos += w * h;
177 if (pos > num || w * h == 0) break;
178 count++;
179 }
180
181 return count;
182 }
183
184
185 long *get_best_icon (long *data, int icon_count, int num, int *iw, int *ih, int best_icon_size)
186 {
187 int width[icon_count], height[icon_count], pos, i, w, h;
188 long *icon_data[icon_count];
189
190 /* List up icons */
191 pos = 0;
192 i = icon_count;
193 while (i--) {
194 w = data[pos++];
195 h = data[pos++];
196 if (pos + w * h > num) break;
197
198 width[i] = w;
199 height[i] = h;
200 icon_data[i] = &data[pos];
201
202 pos += w * h;
203 }
204
205 /* Try to find exact size */
206 int icon_num = -1;
207 for (i = 0; i < icon_count; i++) {
208 if (width[i] == best_icon_size) {
209 icon_num = i;
210 break;
211 }
212 }
213
214 /* Take the biggest or whatever */
215 if (icon_num < 0) {
216 int highest = 0;
217 for (i = 0; i < icon_count; i++) {
218 if (width[i] > highest) {
219 icon_num = i;
220 highest = width[i];
221 }
222 }
223 }
224
225 *iw = width[icon_num];
226 *ih = height[icon_num];
227 return icon_data[icon_num];
228 }
229
230
231 void get_text_size(PangoFontDescription *font, int *height_ink, int *height, int panel_height, char *text, int len)
232 {
233 PangoRectangle rect_ink, rect;
234
235 Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth);
236
237 cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_height);
238 cairo_t *c = cairo_create (cs);
239
240 PangoLayout *layout = pango_cairo_create_layout (c);
241 pango_layout_set_font_description (layout, font);
242 pango_layout_set_text (layout, text, len);
243
244 pango_layout_get_pixel_extents(layout, &rect_ink, &rect);
245 *height_ink = rect_ink.height;
246 *height = rect.height;
247 //printf("dimension : %d - %d\n", rect_ink.height, rect.height);
248
249 g_object_unref (layout);
250 cairo_destroy (c);
251 cairo_surface_destroy (cs);
252 XFreePixmap (server.dsp, pmap);
253 }
254
255
This page took 0.04986 seconds and 4 git commands to generate.