]> Dogcows Code - chaz/openbox/blob - openbox/screen.c
move ob_pointer_pos to screen_pointer_pos
[chaz/openbox] / openbox / screen.c
1 #include "openbox.h"
2 #include "dock.h"
3 #include "xerror.h"
4 #include "prop.h"
5 #include "startup.h"
6 #include "timer.h"
7 #include "config.h"
8 #include "screen.h"
9 #include "client.h"
10 #include "frame.h"
11 #include "focus.h"
12 #include "dispatch.h"
13 #include "extensions.h"
14 #include "render/render.h"
15
16 #ifdef USE_LIBSN
17 # define SN_API_NOT_YET_FROZEN
18 # include <libsn/sn.h>
19 #endif
20
21 #include <X11/Xlib.h>
22 #ifdef HAVE_UNISTD_H
23 # include <sys/types.h>
24 # include <unistd.h>
25 #endif
26
27 /*! The event mask to grab on the root window */
28 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
29 EnterWindowMask | LeaveWindowMask | \
30 SubstructureNotifyMask | SubstructureRedirectMask | \
31 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
32
33 guint screen_num_desktops;
34 guint screen_num_monitors;
35 guint screen_desktop;
36 Size screen_physical_size;
37 gboolean screen_showing_desktop;
38 DesktopLayout screen_desktop_layout;
39 char **screen_desktop_names;
40 Window screen_support_win;
41
42 static Rect **area; /* array of desktop holding array of xinerama areas */
43 static Rect *monitor_area;
44
45 #ifdef USE_LIBSN
46 static SnMonitorContext *sn_context;
47 static int sn_busy_cnt;
48 static ObTimer *sn_timer;
49
50 static void sn_event_func(SnMonitorEvent *event, void *data);
51 #endif
52
53 static void set_root_cursor();
54
55 gboolean screen_annex()
56 {
57 XSetWindowAttributes attrib;
58 pid_t pid;
59 gint i, num_support;
60 guint32 *supported;
61
62 xerror_set_ignore(TRUE);
63 xerror_occured = FALSE;
64 XSelectInput(ob_display, RootWindow(ob_display, ob_screen),
65 ROOT_EVENTMASK);
66 xerror_set_ignore(FALSE);
67 if (xerror_occured) {
68 g_message("A window manager is already running on screen %d",
69 ob_screen);
70 return FALSE;
71 }
72
73
74 g_message("Managing screen %d", ob_screen);
75
76 set_root_cursor();
77
78 /* set the OPENBOX_PID hint */
79 pid = getpid();
80 PROP_SET32(RootWindow(ob_display, ob_screen),
81 openbox_pid, cardinal, pid);
82
83 /* create the netwm support window */
84 attrib.override_redirect = TRUE;
85 screen_support_win = XCreateWindow(ob_display,
86 RootWindow(ob_display, ob_screen),
87 -100, -100, 1, 1, 0,
88 CopyFromParent, InputOutput,
89 CopyFromParent,
90 CWOverrideRedirect, &attrib);
91 XMapRaised(ob_display, screen_support_win);
92
93 /* set supporting window */
94 PROP_SET32(RootWindow(ob_display, ob_screen),
95 net_supporting_wm_check, window, screen_support_win);
96
97 /* set properties on the supporting window */
98 PROP_SETS(screen_support_win, net_wm_name, "Openbox");
99 PROP_SET32(screen_support_win, net_supporting_wm_check,
100 window, screen_support_win);
101
102 /* set the _NET_SUPPORTED_ATOMS hint */
103 num_support = 61;
104 i = 0;
105 supported = g_new(guint32, num_support);
106 supported[i++] = prop_atoms.net_current_desktop;
107 supported[i++] = prop_atoms.net_number_of_desktops;
108 supported[i++] = prop_atoms.net_desktop_geometry;
109 supported[i++] = prop_atoms.net_desktop_viewport;
110 supported[i++] = prop_atoms.net_active_window;
111 supported[i++] = prop_atoms.net_workarea;
112 supported[i++] = prop_atoms.net_client_list;
113 supported[i++] = prop_atoms.net_client_list_stacking;
114 supported[i++] = prop_atoms.net_desktop_names;
115 supported[i++] = prop_atoms.net_close_window;
116 supported[i++] = prop_atoms.net_desktop_layout;
117 supported[i++] = prop_atoms.net_showing_desktop;
118 supported[i++] = prop_atoms.net_wm_name;
119 supported[i++] = prop_atoms.net_wm_visible_name;
120 supported[i++] = prop_atoms.net_wm_icon_name;
121 supported[i++] = prop_atoms.net_wm_visible_icon_name;
122 supported[i++] = prop_atoms.net_wm_desktop;
123 supported[i++] = prop_atoms.net_wm_strut;
124 supported[i++] = prop_atoms.net_wm_window_type;
125 supported[i++] = prop_atoms.net_wm_window_type_desktop;
126 supported[i++] = prop_atoms.net_wm_window_type_dock;
127 supported[i++] = prop_atoms.net_wm_window_type_toolbar;
128 supported[i++] = prop_atoms.net_wm_window_type_menu;
129 supported[i++] = prop_atoms.net_wm_window_type_utility;
130 supported[i++] = prop_atoms.net_wm_window_type_splash;
131 supported[i++] = prop_atoms.net_wm_window_type_dialog;
132 supported[i++] = prop_atoms.net_wm_window_type_normal;
133 supported[i++] = prop_atoms.net_wm_allowed_actions;
134 supported[i++] = prop_atoms.net_wm_action_move;
135 supported[i++] = prop_atoms.net_wm_action_resize;
136 supported[i++] = prop_atoms.net_wm_action_minimize;
137 supported[i++] = prop_atoms.net_wm_action_shade;
138 supported[i++] = prop_atoms.net_wm_action_maximize_horz;
139 supported[i++] = prop_atoms.net_wm_action_maximize_vert;
140 supported[i++] = prop_atoms.net_wm_action_fullscreen;
141 supported[i++] = prop_atoms.net_wm_action_change_desktop;
142 supported[i++] = prop_atoms.net_wm_action_close;
143 supported[i++] = prop_atoms.net_wm_state;
144 supported[i++] = prop_atoms.net_wm_state_modal;
145 supported[i++] = prop_atoms.net_wm_state_maximized_vert;
146 supported[i++] = prop_atoms.net_wm_state_maximized_horz;
147 supported[i++] = prop_atoms.net_wm_state_shaded;
148 supported[i++] = prop_atoms.net_wm_state_skip_taskbar;
149 supported[i++] = prop_atoms.net_wm_state_skip_pager;
150 supported[i++] = prop_atoms.net_wm_state_hidden;
151 supported[i++] = prop_atoms.net_wm_state_fullscreen;
152 supported[i++] = prop_atoms.net_wm_state_above;
153 supported[i++] = prop_atoms.net_wm_state_below;
154 supported[i++] = prop_atoms.net_moveresize_window;
155 supported[i++] = prop_atoms.net_wm_moveresize;
156 supported[i++] = prop_atoms.net_wm_moveresize_size_topleft;
157 supported[i++] = prop_atoms.net_wm_moveresize_size_top;
158 supported[i++] = prop_atoms.net_wm_moveresize_size_topright;
159 supported[i++] = prop_atoms.net_wm_moveresize_size_right;
160 supported[i++] = prop_atoms.net_wm_moveresize_size_bottomright;
161 supported[i++] = prop_atoms.net_wm_moveresize_size_bottom;
162 supported[i++] = prop_atoms.net_wm_moveresize_size_bottomleft;
163 supported[i++] = prop_atoms.net_wm_moveresize_size_left;
164 supported[i++] = prop_atoms.net_wm_moveresize_move;
165 supported[i++] = prop_atoms.net_wm_moveresize_size_keyboard;
166 supported[i++] = prop_atoms.net_wm_moveresize_move_keyboard;
167 g_assert(i == num_support);
168 /*
169 supported[] = prop_atoms.net_wm_action_stick;
170 */
171
172 PROP_SETA32(RootWindow(ob_display, ob_screen),
173 net_supported, atom, supported, num_support);
174 g_free(supported);
175
176 return TRUE;
177 }
178
179 void screen_startup()
180 {
181 GSList *it;
182 guint i;
183
184 /* get the initial size */
185 screen_resize();
186
187 /* set the names */
188 screen_desktop_names = g_new(char*,
189 g_slist_length(config_desktops_names) + 1);
190 for (i = 0, it = config_desktops_names; it; ++i, it = it->next)
191 screen_desktop_names[i] = it->data; /* dont strdup */
192 screen_desktop_names[i] = NULL;
193 PROP_SETSS(RootWindow(ob_display, ob_screen),
194 net_desktop_names, screen_desktop_names);
195 g_free(screen_desktop_names); /* dont free the individual strings */
196 screen_desktop_names = NULL;
197
198 screen_num_desktops = 0;
199 screen_set_num_desktops(config_desktops_num);
200 if (startup_desktop >= screen_num_desktops)
201 startup_desktop = 0;
202 screen_desktop = startup_desktop;
203 screen_set_desktop(startup_desktop);
204
205 /* don't start in showing-desktop mode */
206 screen_showing_desktop = FALSE;
207 PROP_SET32(RootWindow(ob_display, ob_screen),
208 net_showing_desktop, cardinal, screen_showing_desktop);
209
210 screen_update_layout();
211
212 #ifdef USE_LIBSN
213 sn_context = sn_monitor_context_new(ob_sn_display, ob_screen,
214 sn_event_func, NULL, NULL);
215 sn_busy_cnt = 0;
216 #endif
217 }
218
219 void screen_shutdown()
220 {
221 Rect **r;
222
223 XSelectInput(ob_display, RootWindow(ob_display, ob_screen), NoEventMask);
224
225 /* we're not running here no more! */
226 PROP_ERASE(RootWindow(ob_display, ob_screen), openbox_pid);
227 /* not without us */
228 PROP_ERASE(RootWindow(ob_display, ob_screen), net_supported);
229 /* don't keep this mode */
230 PROP_ERASE(RootWindow(ob_display, ob_screen), net_showing_desktop);
231
232 XDestroyWindow(ob_display, screen_support_win);
233
234 g_strfreev(screen_desktop_names);
235 for (r = area; *r; ++r)
236 g_free(*r);
237 g_free(area);
238 }
239
240 void screen_resize()
241 {
242 static int oldw = 0, oldh = 0;
243 int w, h;
244 GList *it;
245 guint32 geometry[2];
246
247 w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen));
248 h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen));
249
250 if (w == oldw && h == oldh) return;
251
252 oldw = w; oldh = h;
253
254 /* Set the _NET_DESKTOP_GEOMETRY hint */
255 screen_physical_size.width = geometry[0] = w;
256 screen_physical_size.height = geometry[1] = h;
257 PROP_SETA32(RootWindow(ob_display, ob_screen),
258 net_desktop_geometry, cardinal, geometry, 2);
259
260 if (ob_state() == OB_STATE_STARTING)
261 return;
262
263 dock_configure();
264 screen_update_areas();
265
266 for (it = client_list; it; it = it->next)
267 client_move_onscreen(it->data);
268 }
269
270 void screen_set_num_desktops(guint num)
271 {
272 guint i, old;
273 guint32 *viewport;
274 GList *it;
275
276 g_assert(num > 0);
277
278 old = screen_num_desktops;
279 screen_num_desktops = num;
280 PROP_SET32(RootWindow(ob_display, ob_screen),
281 net_number_of_desktops, cardinal, num);
282
283 /* set the viewport hint */
284 viewport = g_new0(guint32, num * 2);
285 PROP_SETA32(RootWindow(ob_display, ob_screen),
286 net_desktop_viewport, cardinal, viewport, num * 2);
287 g_free(viewport);
288
289 /* the number of rows/columns will differ */
290 screen_update_layout();
291
292 /* may be some unnamed desktops that we need to fill in with names */
293 screen_update_desktop_names();
294
295 /* update the focus lists */
296 /* free our lists for the desktops which have disappeared */
297 for (i = num; i < old; ++i)
298 g_list_free(focus_order[i]);
299 /* realloc the array */
300 focus_order = g_renew(GList*, focus_order, num);
301 /* set the new lists to be empty */
302 for (i = old; i < num; ++i)
303 focus_order[i] = NULL;
304
305 /* move windows on desktops that will no longer exist! */
306 for (it = client_list; it != NULL; it = it->next) {
307 ObClient *c = it->data;
308 if (c->desktop >= num && c->desktop != DESKTOP_ALL)
309 client_set_desktop(c, num - 1, FALSE);
310 }
311
312 /* change our struts/area to match (after moving windows) */
313 screen_update_areas();
314
315 dispatch_ob(Event_Ob_NumDesktops, num, old);
316
317 /* change our desktop if we're on one that no longer exists! */
318 if (screen_desktop >= screen_num_desktops)
319 screen_set_desktop(num - 1);
320 }
321
322 void screen_set_desktop(guint num)
323 {
324 GList *it;
325 guint old;
326 XEvent e;
327
328 g_assert(num < screen_num_desktops);
329
330 old = screen_desktop;
331 screen_desktop = num;
332 PROP_SET32(RootWindow(ob_display, ob_screen),
333 net_current_desktop, cardinal, num);
334
335 if (old == num) return;
336
337 g_message("Moving to desktop %d", num+1);
338
339 /* show windows before hiding the rest to lessen the enter/leave events */
340
341 /* show windows from top to bottom */
342 for (it = stacking_list; it != NULL; it = it->next) {
343 if (WINDOW_IS_CLIENT(it->data)) {
344 ObClient *c = it->data;
345 if (!c->frame->visible && client_should_show(c))
346 frame_show(c->frame);
347 }
348 }
349
350 /* hide windows from bottom to top */
351 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
352 if (WINDOW_IS_CLIENT(it->data)) {
353 ObClient *c = it->data;
354 if (c->frame->visible && !client_should_show(c))
355 frame_hide(c->frame);
356 }
357 }
358
359 /* focus the last focused window on the desktop, and ignore enter events
360 from the switch so it doesnt mess with the focus */
361 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
362 #ifdef DEBUG_FOCUS
363 g_message("switch fallback");
364 #endif
365 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP);
366 #ifdef DEBUG_FOCUS
367 g_message("/switch fallback");
368 #endif
369
370 dispatch_ob(Event_Ob_Desktop, num, old);
371 }
372
373 void screen_update_layout()
374 {
375 ObOrientation orient;
376 ObCorner corner;
377 guint rows;
378 guint cols;
379 guint32 *data;
380 guint num;
381 gboolean valid = FALSE;
382
383 if (PROP_GETA32(RootWindow(ob_display, ob_screen),
384 net_desktop_layout, cardinal, &data, &num)) {
385 if (num == 3 || num == 4) {
386
387 if (data[0] == prop_atoms.net_wm_orientation_vert)
388 orient = OB_ORIENTATION_VERT;
389 else if (data[0] == prop_atoms.net_wm_orientation_horz)
390 orient = OB_ORIENTATION_HORZ;
391 else
392 goto screen_update_layout_bail;
393
394 if (num < 4)
395 corner = OB_CORNER_TOPLEFT;
396 else {
397 if (data[3] == prop_atoms.net_wm_topright)
398 corner = OB_CORNER_TOPRIGHT;
399 else if (data[3] == prop_atoms.net_wm_bottomright)
400 corner = OB_CORNER_BOTTOMRIGHT;
401 else if (data[3] == prop_atoms.net_wm_bottomleft)
402 corner = OB_CORNER_BOTTOMLEFT;
403 else
404 goto screen_update_layout_bail;
405 }
406
407 /* fill in a zero rows/columns */
408 if ((data[1] == 0 && data[2] == 0) || /* both 0's is bad data.. */
409 (data[1] != 0 && data[2] != 0)) { /* no 0's is bad data.. */
410 goto screen_update_layout_bail;
411 } else {
412 if (data[1] == 0) {
413 data[1] = (screen_num_desktops +
414 screen_num_desktops % data[2]) / data[2];
415 } else if (data[2] == 0) {
416 data[2] = (screen_num_desktops +
417 screen_num_desktops % data[1]) / data[1];
418 }
419 cols = data[1];
420 rows = data[2];
421 }
422
423 /* bounds checking */
424 if (orient == OB_ORIENTATION_HORZ) {
425 rows = MIN(rows, screen_num_desktops);
426 cols = MIN(cols, ((screen_num_desktops +
427 (screen_num_desktops % rows)) / rows));
428 } else {
429 cols = MIN(cols, screen_num_desktops);
430 rows = MIN(rows, ((screen_num_desktops +
431 (screen_num_desktops % cols)) / cols));
432 }
433
434 valid = TRUE;
435 }
436 screen_update_layout_bail:
437 g_free(data);
438 }
439
440 if (!valid) {
441 /* defaults */
442 orient = OB_ORIENTATION_HORZ;
443 corner = OB_CORNER_TOPLEFT;
444 rows = 1;
445 cols = screen_num_desktops;
446 }
447
448 screen_desktop_layout.orientation = orient;
449 screen_desktop_layout.start_corner = corner;
450 screen_desktop_layout.rows = rows;
451 screen_desktop_layout.columns = cols;
452 }
453
454 void screen_update_desktop_names()
455 {
456 guint i;
457
458 /* empty the array */
459 g_strfreev(screen_desktop_names);
460 screen_desktop_names = NULL;
461
462 if (PROP_GETSS(RootWindow(ob_display, ob_screen),
463 net_desktop_names, utf8, &screen_desktop_names))
464 for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
465 else
466 i = 0;
467 if (i <= screen_num_desktops) {
468 screen_desktop_names = g_renew(char*, screen_desktop_names,
469 screen_num_desktops + 1);
470 screen_desktop_names[screen_num_desktops] = NULL;
471 for (; i < screen_num_desktops; ++i)
472 screen_desktop_names[i] = g_strdup("Unnamed Desktop");
473 }
474 }
475
476 void screen_show_desktop(gboolean show)
477 {
478 GList *it;
479
480 if (show == screen_showing_desktop) return; /* no change */
481
482 screen_showing_desktop = show;
483
484 if (show) {
485 /* bottom to top */
486 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
487 if (WINDOW_IS_CLIENT(it->data)) {
488 ObClient *client = it->data;
489 if (client->frame->visible && !client_should_show(client))
490 frame_hide(client->frame);
491 }
492 }
493 } else {
494 /* top to bottom */
495 for (it = stacking_list; it != NULL; it = it->next) {
496 if (WINDOW_IS_CLIENT(it->data)) {
497 ObClient *client = it->data;
498 if (!client->frame->visible && client_should_show(client))
499 frame_show(client->frame);
500 }
501 }
502 }
503
504 if (show) {
505 /* focus desktop */
506 for (it = focus_order[screen_desktop]; it; it = it->next)
507 if (((ObClient*)it->data)->type == OB_CLIENT_TYPE_DESKTOP &&
508 client_focus(it->data))
509 break;
510 } else {
511 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
512 }
513
514 show = !!show; /* make it boolean */
515 PROP_SET32(RootWindow(ob_display, ob_screen),
516 net_showing_desktop, cardinal, show);
517
518 dispatch_ob(Event_Ob_ShowDesktop, show, 0);
519 }
520
521 void screen_install_colormap(ObClient *client, gboolean install)
522 {
523 XWindowAttributes wa;
524
525 if (client == NULL) {
526 if (install)
527 XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
528 else
529 XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
530 } else {
531 if (XGetWindowAttributes(ob_display, client->window, &wa) &&
532 wa.colormap != None) {
533 xerror_set_ignore(TRUE);
534 if (install)
535 XInstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
536 else
537 XUninstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
538 xerror_set_ignore(FALSE);
539 }
540 }
541 }
542
543 void screen_update_areas()
544 {
545 guint i, x;
546 guint32 *dims;
547 Rect **old_area = area;
548 Rect **rit;
549 GList *it;
550
551 g_free(monitor_area);
552 extensions_xinerama_screens(&monitor_area, &screen_num_monitors);
553
554 if (area) {
555 for (i = 0; area[i]; ++i)
556 g_free(area[i]);
557 g_free(area);
558 }
559
560 area = g_new(Rect*, screen_num_desktops + 2);
561 for (i = 0; i < screen_num_desktops + 1; ++i)
562 area[i] = g_new(Rect, screen_num_monitors + 1);
563 area[i] = NULL;
564
565 dims = g_new(guint32, 4 * screen_num_desktops);
566
567 rit = old_area;
568 for (i = 0; i < screen_num_desktops + 1; ++i) {
569 Strut s;
570 int l, r, t, b;
571
572 /* calc the xinerama areas */
573 for (x = 0; x < screen_num_monitors; ++x) {
574 area[i][x] = monitor_area[x];
575 if (x == 0) {
576 l = monitor_area[x].x;
577 t = monitor_area[x].y;
578 r = monitor_area[x].x + monitor_area[x].width - 1;
579 b = monitor_area[x].y + monitor_area[x].height - 1;
580 } else {
581 l = MIN(l, monitor_area[x].x);
582 t = MIN(t, monitor_area[x].y);
583 r = MAX(r, monitor_area[x].x + monitor_area[x].width - 1);
584 b = MAX(b, monitor_area[x].y + monitor_area[x].height - 1);
585 }
586 }
587 RECT_SET(area[i][x], l, t, r - l + 1, b - t + 1);
588
589 /* apply struts */
590 STRUT_SET(s, 0, 0, 0, 0);
591 for (it = client_list; it; it = it->next)
592 STRUT_ADD(s, ((ObClient*)it->data)->strut);
593 STRUT_ADD(s, dock_strut);
594
595 if (s.left) {
596 int o;
597
598 /* find the left-most xin heads, i do this in 2 loops :| */
599 o = area[i][0].x;
600 for (x = 1; x < screen_num_monitors; ++x)
601 o = MIN(o, area[i][x].x);
602
603 for (x = 0; x < screen_num_monitors; ++x) {
604 int edge = o + s.left - area[i][x].x;
605 if (edge > 0) {
606 area[i][x].x += edge;
607 area[i][x].width -= edge;
608 }
609 }
610
611 area[i][screen_num_monitors].x += s.left;
612 area[i][screen_num_monitors].width -= s.left;
613 }
614 if (s.top) {
615 int o;
616
617 /* find the left-most xin heads, i do this in 2 loops :| */
618 o = area[i][0].y;
619 for (x = 1; x < screen_num_monitors; ++x)
620 o = MIN(o, area[i][x].y);
621
622 for (x = 0; x < screen_num_monitors; ++x) {
623 int edge = o + s.top - area[i][x].y;
624 if (edge > 0) {
625 area[i][x].y += edge;
626 area[i][x].height -= edge;
627 }
628 }
629
630 area[i][screen_num_monitors].y += s.top;
631 area[i][screen_num_monitors].height -= s.top;
632 }
633 if (s.right) {
634 int o;
635
636 /* find the bottom-most xin heads, i do this in 2 loops :| */
637 o = area[i][0].x + area[i][0].width - 1;
638 for (x = 1; x < screen_num_monitors; ++x)
639 o = MAX(o, area[i][x].x + area[i][x].width - 1);
640
641 for (x = 0; x < screen_num_monitors; ++x) {
642 int edge = (area[i][x].x + area[i][x].width - 1) -
643 (o - s.right);
644 if (edge > 0)
645 area[i][x].width -= edge;
646 }
647
648 area[i][screen_num_monitors].width -= s.right;
649 }
650 if (s.bottom) {
651 int o;
652
653 /* find the bottom-most xin heads, i do this in 2 loops :| */
654 o = area[i][0].y + area[i][0].height - 1;
655 for (x = 1; x < screen_num_monitors; ++x)
656 o = MAX(o, area[i][x].y + area[i][x].height - 1);
657
658 for (x = 0; x < screen_num_monitors; ++x) {
659 int edge = (area[i][x].y + area[i][x].height - 1) -
660 (o - s.bottom);
661 if (edge > 0)
662 area[i][x].height -= edge;
663 }
664
665 area[i][screen_num_monitors].height -= s.bottom;
666 }
667
668 /* XXX when dealing with partial struts, if its in a single
669 xinerama area, then only subtract it from that area's space
670 for (x = 0; x < screen_num_monitors; ++x) {
671 GList *it;
672
673
674 do something smart with it for the 'all xinerama areas' one...
675
676 for (it = client_list; it; it = it->next) {
677
678 XXX if gunna test this shit, then gotta worry about when
679 the client moves between xinerama heads..
680
681 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
682 area[i][x])) {
683
684 }
685 }
686 }
687 */
688
689 /* XXX optimize when this is run? */
690
691 /* the area has changed, adjust all the maximized
692 windows */
693 for (it = client_list; it; it = it->next) {
694 ObClient *c = it->data;
695 if (i < screen_num_desktops) {
696 if (c->desktop == i)
697 client_reconfigure(c);
698 } else if (c->desktop == DESKTOP_ALL)
699 client_reconfigure(c);
700 }
701 if (i < screen_num_desktops) {
702 /* don't set these for the 'all desktops' area */
703 dims[(i * 4) + 0] = area[i][screen_num_monitors].x;
704 dims[(i * 4) + 1] = area[i][screen_num_monitors].y;
705 dims[(i * 4) + 2] = area[i][screen_num_monitors].width;
706 dims[(i * 4) + 3] = area[i][screen_num_monitors].height;
707 }
708 }
709 PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal,
710 dims, 4 * screen_num_desktops);
711
712 g_free(dims);
713 }
714
715 Rect *screen_area(guint desktop)
716 {
717 return screen_area_monitor(desktop, screen_num_monitors);
718 }
719
720 Rect *screen_area_monitor(guint desktop, guint head)
721 {
722 if (head > screen_num_monitors)
723 return NULL;
724 if (desktop >= screen_num_desktops) {
725 if (desktop == DESKTOP_ALL)
726 return &area[screen_num_desktops][head];
727 return NULL;
728 }
729 return &area[desktop][head];
730 }
731
732 Rect *screen_physical_area()
733 {
734 return screen_physical_area_monitor(screen_num_monitors);
735 }
736
737 Rect *screen_physical_area_monitor(guint head)
738 {
739 if (head > screen_num_monitors)
740 return NULL;
741 return &monitor_area[head];
742 }
743
744 static void set_root_cursor()
745 {
746 #ifdef USE_LIBSN
747 if (sn_busy_cnt)
748 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
749 ob_cursor(OB_CURSOR_BUSY));
750 else
751 #endif
752 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
753 ob_cursor(OB_CURSOR_POINTER));
754 }
755
756 #ifdef USE_LIBSN
757 static void sn_timeout(void *data)
758 {
759 timer_stop(sn_timer);
760 sn_timer = NULL;
761 sn_busy_cnt = 0;
762
763 set_root_cursor();
764 }
765
766 static void sn_event_func(SnMonitorEvent *ev, void *data)
767 {
768 SnStartupSequence *seq;
769 const char *seq_id, *bin_name;
770 int cnt = sn_busy_cnt;
771
772 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
773 return;
774
775 seq_id = sn_startup_sequence_get_id(seq);
776 bin_name = sn_startup_sequence_get_binary_name(seq);
777
778 if (!(seq_id && bin_name))
779 return;
780
781 switch (sn_monitor_event_get_type(ev)) {
782 case SN_MONITOR_EVENT_INITIATED:
783 ++sn_busy_cnt;
784 if (sn_timer)
785 timer_stop(sn_timer);
786 /* 30 second timeout for apps to start */
787 sn_timer = timer_start(30 * 1000000, sn_timeout, NULL);
788 break;
789 case SN_MONITOR_EVENT_CHANGED:
790 break;
791 case SN_MONITOR_EVENT_COMPLETED:
792 if (sn_busy_cnt) --sn_busy_cnt;
793 if (sn_timer) {
794 timer_stop(sn_timer);
795 sn_timer = NULL;
796 }
797 break;
798 case SN_MONITOR_EVENT_CANCELED:
799 if (sn_busy_cnt) --sn_busy_cnt;
800 if (sn_timer) {
801 timer_stop(sn_timer);
802 sn_timer = NULL;
803 }
804 };
805
806 if (sn_busy_cnt != cnt)
807 set_root_cursor();
808 }
809 #endif
810
811 gboolean screen_pointer_pos(int *x, int *y)
812 {
813 Window w;
814 int i;
815 guint u;
816
817 return !!XQueryPointer(ob_display, RootWindow(ob_display, ob_screen),
818 &w, &w, x, y, &i, &i, &u);
819 }
This page took 0.075072 seconds and 5 git commands to generate.