]> icculus.org git repositories - dana/openbox.git/blob - openbox/screen.c
add xerror.h
[dana/openbox.git] / 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    = 0;
34 guint    screen_desktop         = 0;
35 Size     screen_physical_size;
36 gboolean screen_showing_desktop;
37 DesktopLayout screen_desktop_layout;
38 char   **screen_desktop_names = NULL;
39
40 static Rect  *area = NULL;
41 static Strut *strut = NULL;
42 static Window support_window = None;
43
44 #ifdef USE_LIBSN
45 static SnMonitorContext *sn_context;
46 static int sn_busy_cnt;
47 static Timer *sn_timer = NULL;
48
49 static void sn_event_func(SnMonitorEvent *event, void *data);
50 #endif
51
52 static void screen_update_area();
53 static void set_root_cursor();
54
55 static gboolean running;
56 static int another_running(Display *d, XErrorEvent *e)
57 {
58     (void)d;(void)e;
59     g_message("A window manager is already running on screen %d",
60               ob_screen);
61     running = TRUE;
62     return -1;
63 }
64
65 gboolean screen_annex()
66 {
67     XErrorHandler old;
68     pid_t pid;
69     int i, num_support;
70     guint32 *supported;
71
72     running = FALSE;
73     old = XSetErrorHandler(another_running);
74     XSelectInput(ob_display, ob_root, ROOT_EVENTMASK);
75     XSync(ob_display, FALSE);
76     XSetErrorHandler(old);
77     if (running)
78         return FALSE;
79
80     g_message("Managing screen %d", ob_screen);
81
82     set_root_cursor();
83
84     /* set the OPENBOX_PID hint */
85     pid = getpid();
86     PROP_SET32(ob_root, openbox_pid, cardinal, pid);
87
88     /* create the netwm support window */
89     support_window = XCreateSimpleWindow(ob_display, ob_root, 0,0,1,1,0,0,0);
90
91     /* set supporting window */
92     PROP_SET32(ob_root, net_supporting_wm_check, window, support_window);
93
94     /* set properties on the supporting window */
95     PROP_SETS(support_window, net_wm_name, "Openbox3");
96     PROP_SET32(support_window, net_supporting_wm_check, window,support_window);
97
98     /* set the _NET_SUPPORTED_ATOMS hint */
99     num_support = 61;
100     i = 0;
101     supported = g_new(guint32, num_support);
102     supported[i++] = prop_atoms.net_current_desktop;
103     supported[i++] = prop_atoms.net_number_of_desktops;
104     supported[i++] = prop_atoms.net_desktop_geometry;
105     supported[i++] = prop_atoms.net_desktop_viewport;
106     supported[i++] = prop_atoms.net_active_window;
107     supported[i++] = prop_atoms.net_workarea;
108     supported[i++] = prop_atoms.net_client_list;
109     supported[i++] = prop_atoms.net_client_list_stacking;
110     supported[i++] = prop_atoms.net_desktop_names;
111     supported[i++] = prop_atoms.net_close_window;
112     supported[i++] = prop_atoms.net_desktop_layout;
113     supported[i++] = prop_atoms.net_showing_desktop;
114     supported[i++] = prop_atoms.net_wm_name;
115     supported[i++] = prop_atoms.net_wm_visible_name;
116     supported[i++] = prop_atoms.net_wm_icon_name;
117     supported[i++] = prop_atoms.net_wm_visible_icon_name;
118     supported[i++] = prop_atoms.net_wm_desktop;
119     supported[i++] = prop_atoms.net_wm_strut;
120     supported[i++] = prop_atoms.net_wm_window_type;
121     supported[i++] = prop_atoms.net_wm_window_type_desktop;
122     supported[i++] = prop_atoms.net_wm_window_type_dock;
123     supported[i++] = prop_atoms.net_wm_window_type_toolbar;
124     supported[i++] = prop_atoms.net_wm_window_type_menu;
125     supported[i++] = prop_atoms.net_wm_window_type_utility;
126     supported[i++] = prop_atoms.net_wm_window_type_splash;
127     supported[i++] = prop_atoms.net_wm_window_type_dialog;
128     supported[i++] = prop_atoms.net_wm_window_type_normal;
129     supported[i++] = prop_atoms.net_wm_allowed_actions;
130     supported[i++] = prop_atoms.net_wm_action_move;
131     supported[i++] = prop_atoms.net_wm_action_resize;
132     supported[i++] = prop_atoms.net_wm_action_minimize;
133     supported[i++] = prop_atoms.net_wm_action_shade;
134     supported[i++] = prop_atoms.net_wm_action_maximize_horz;
135     supported[i++] = prop_atoms.net_wm_action_maximize_vert;
136     supported[i++] = prop_atoms.net_wm_action_fullscreen;
137     supported[i++] = prop_atoms.net_wm_action_change_desktop;
138     supported[i++] = prop_atoms.net_wm_action_close;
139     supported[i++] = prop_atoms.net_wm_state;
140     supported[i++] = prop_atoms.net_wm_state_modal;
141     supported[i++] = prop_atoms.net_wm_state_maximized_vert;
142     supported[i++] = prop_atoms.net_wm_state_maximized_horz;
143     supported[i++] = prop_atoms.net_wm_state_shaded;
144     supported[i++] = prop_atoms.net_wm_state_skip_taskbar;
145     supported[i++] = prop_atoms.net_wm_state_skip_pager;
146     supported[i++] = prop_atoms.net_wm_state_hidden;
147     supported[i++] = prop_atoms.net_wm_state_fullscreen;
148     supported[i++] = prop_atoms.net_wm_state_above;
149     supported[i++] = prop_atoms.net_wm_state_below;
150     supported[i++] = prop_atoms.net_moveresize_window;
151     supported[i++] = prop_atoms.net_wm_moveresize;
152     supported[i++] = prop_atoms.net_wm_moveresize_size_topleft;
153     supported[i++] = prop_atoms.net_wm_moveresize_size_top;
154     supported[i++] = prop_atoms.net_wm_moveresize_size_topright;
155     supported[i++] = prop_atoms.net_wm_moveresize_size_right;
156     supported[i++] = prop_atoms.net_wm_moveresize_size_bottomright;
157     supported[i++] = prop_atoms.net_wm_moveresize_size_bottom;
158     supported[i++] = prop_atoms.net_wm_moveresize_size_bottomleft;
159     supported[i++] = prop_atoms.net_wm_moveresize_size_left;
160     supported[i++] = prop_atoms.net_wm_moveresize_move;
161     supported[i++] = prop_atoms.net_wm_moveresize_size_keyboard;
162     supported[i++] = prop_atoms.net_wm_moveresize_move_keyboard;
163     g_assert(i == num_support);
164 /*
165   supported[] = prop_atoms.net_wm_action_stick;
166 */
167
168     PROP_SETA32(ob_root, net_supported, atom, supported, num_support);
169     g_free(supported);
170
171     return TRUE;
172 }
173
174 void screen_startup()
175 {
176     GSList *it;
177     guint i;
178
179     /* get the initial size */
180     screen_resize(WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)),
181                   HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen)));
182
183     /* set the names */
184     screen_desktop_names = g_new(char*,
185                                  g_slist_length(config_desktops_names) + 1);
186     for (i = 0, it = config_desktops_names; it; ++i, it = it->next)
187         screen_desktop_names[i] = it->data; /* dont strdup */
188     screen_desktop_names[i] = NULL;
189     PROP_SETSS(ob_root, net_desktop_names, screen_desktop_names);
190     g_free(screen_desktop_names); /* dont free the individual strings */
191     screen_desktop_names = NULL;
192
193     screen_num_desktops = 0;
194     screen_set_num_desktops(config_desktops_num);
195     if (startup_desktop >= screen_num_desktops)
196         startup_desktop = 0;
197     screen_desktop = startup_desktop;
198     screen_set_desktop(startup_desktop);
199
200     /* don't start in showing-desktop mode */
201     screen_showing_desktop = FALSE;
202     PROP_SET32(ob_root, net_showing_desktop, cardinal, screen_showing_desktop);
203
204     screen_update_layout();
205
206 #ifdef USE_LIBSN
207     sn_context = sn_monitor_context_new(ob_sn_display, ob_screen,
208                                         sn_event_func, NULL, NULL);
209     sn_busy_cnt = 0;
210 #endif
211 }
212
213 void screen_shutdown()
214 {
215     XSelectInput(ob_display, ob_root, NoEventMask);
216
217     PROP_ERASE(ob_root, openbox_pid); /* we're not running here no more! */
218     PROP_ERASE(ob_root, net_supported); /* not without us */
219     PROP_ERASE(ob_root, net_showing_desktop); /* don't keep this mode */
220
221     XDestroyWindow(ob_display, support_window);
222
223     g_strfreev(screen_desktop_names);
224     g_free(strut);
225     g_free(area);
226 }
227
228 void screen_resize(int w, int h)
229 {
230     GList *it;
231     guint32 geometry[2];
232
233     /* Set the _NET_DESKTOP_GEOMETRY hint */
234     geometry[0] = w;
235     geometry[1] = h;
236     PROP_SETA32(ob_root, net_desktop_geometry, cardinal, geometry, 2);
237     screen_physical_size.width = geometry[0];
238     screen_physical_size.height = geometry[1];
239
240     if (ob_state == State_Starting)
241         return;
242
243     dock_configure();
244     screen_update_struts();
245
246     for (it = client_list; it; it = it->next)
247         client_move_onscreen(it->data);
248 }
249
250 void screen_set_num_desktops(guint num)
251 {
252     guint i, old;
253     guint32 *viewport;
254     GList *it;
255
256     g_assert(num > 0);
257
258     old = screen_num_desktops;
259     screen_num_desktops = num;
260     PROP_SET32(ob_root, net_number_of_desktops, cardinal, num);
261
262     /* set the viewport hint */
263     viewport = g_new0(guint32, num * 2);
264     PROP_SETA32(ob_root, net_desktop_viewport, cardinal, viewport, num * 2);
265     g_free(viewport);
266
267     /* the number of rows/columns will differ */
268     screen_update_layout();
269
270     /* may be some unnamed desktops that we need to fill in with names */
271     screen_update_desktop_names();
272
273     /* update the focus lists */
274     /* free our lists for the desktops which have disappeared */
275     for (i = num; i < old; ++i)
276         g_list_free(focus_order[i]);
277     /* realloc the array */
278     focus_order = g_renew(GList*, focus_order, num);
279     /* set the new lists to be empty */
280     for (i = old; i < num; ++i)
281         focus_order[i] = NULL;
282
283     /* move windows on desktops that will no longer exist! */
284     for (it = client_list; it != NULL; it = it->next) {
285         Client *c = it->data;
286         if (c->desktop >= num && c->desktop != DESKTOP_ALL)
287             client_set_desktop(c, num - 1, FALSE);
288     }
289
290     /* change our struts/area to match (after moving windows) */
291     screen_update_struts();
292
293     dispatch_ob(Event_Ob_NumDesktops, num, old);
294
295     /* change our desktop if we're on one that no longer exists! */
296     if (screen_desktop >= screen_num_desktops)
297         screen_set_desktop(num - 1);
298 }
299
300 void screen_set_desktop(guint num)
301 {
302     GList *it;
303     guint old;
304     XEvent e;
305      
306     g_assert(num < screen_num_desktops);
307
308     old = screen_desktop;
309     screen_desktop = num;
310     PROP_SET32(ob_root, net_current_desktop, cardinal, num);
311
312     if (old == num) return;
313
314     g_message("Moving to desktop %d", num+1);
315
316     /* show windows before hiding the rest to lessen the enter/leave events */
317
318     /* show windows from top to bottom */
319     for (it = stacking_list; it != NULL; it = it->next) {
320         if (WINDOW_IS_CLIENT(it->data)) {
321             Client *c = it->data;
322             if (!c->frame->visible && client_should_show(c))
323                 frame_show(c->frame);
324         }
325     }
326
327     /* hide windows from bottom to top */
328     for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
329         if (WINDOW_IS_CLIENT(it->data)) {
330             Client *c = it->data;
331             if (c->frame->visible && !client_should_show(c))
332                 frame_hide(c->frame);
333         }
334     }
335
336     /* focus the last focused window on the desktop, and ignore enter events
337        from the switch so it doesnt mess with the focus */
338     while (XCheckTypedEvent(ob_display, EnterNotify, &e));
339     focus_fallback(Fallback_Desktop);
340
341     dispatch_ob(Event_Ob_Desktop, num, old);
342 }
343
344 void screen_update_layout()
345 {
346     guint32 *data = NULL;
347     guint num;
348
349     /* defaults */
350     screen_desktop_layout.orientation = prop_atoms.net_wm_orientation_horz;
351     screen_desktop_layout.start_corner = prop_atoms.net_wm_topleft;
352     screen_desktop_layout.rows = 1;
353     screen_desktop_layout.columns = screen_num_desktops;
354
355     if (PROP_GETA32(ob_root, net_desktop_layout, cardinal, &data, &num)) {
356         if (num == 3 || num == 4) {
357             if (data[0] == prop_atoms.net_wm_orientation_vert)
358                 screen_desktop_layout.orientation = data[0];
359             if (num == 3)
360                 screen_desktop_layout.start_corner =
361                     prop_atoms.net_wm_topright;
362             else {
363                 if (data[3] == prop_atoms.net_wm_topright)
364                     screen_desktop_layout.start_corner = data[3];
365                 else if (data[3] == prop_atoms.net_wm_bottomright)
366                     screen_desktop_layout.start_corner = data[3];
367                 else if (data[3] == prop_atoms.net_wm_bottomleft)
368                     screen_desktop_layout.start_corner = data[3];
369             }
370
371             /* fill in a zero rows/columns */
372             if (!(data[1] == 0 && data[2] == 0)) { /* both 0's is bad data.. */
373                 if (data[1] == 0) {
374                     data[1] = (screen_num_desktops +
375                                screen_num_desktops % data[2]) / data[2];
376                 } else if (data[2] == 0) {
377                     data[2] = (screen_num_desktops +
378                                screen_num_desktops % data[1]) / data[1];
379                 }
380                 screen_desktop_layout.columns = data[1];
381                 screen_desktop_layout.rows = data[2];
382             }
383
384             /* bounds checking */
385             if (screen_desktop_layout.orientation ==
386                 prop_atoms.net_wm_orientation_horz) {
387                 if (screen_desktop_layout.rows > screen_num_desktops)
388                     screen_desktop_layout.rows = screen_num_desktops;
389                 if (screen_desktop_layout.columns >
390                     ((screen_num_desktops + screen_num_desktops %
391                       screen_desktop_layout.rows) /
392                      screen_desktop_layout.rows))
393                     screen_desktop_layout.columns =
394                         (screen_num_desktops + screen_num_desktops %
395                          screen_desktop_layout.rows) /
396                         screen_desktop_layout.rows;
397             } else {
398                 if (screen_desktop_layout.columns > screen_num_desktops)
399                     screen_desktop_layout.columns = screen_num_desktops;
400                 if (screen_desktop_layout.rows >
401                     ((screen_num_desktops + screen_num_desktops %
402                       screen_desktop_layout.columns) /
403                      screen_desktop_layout.columns))
404                     screen_desktop_layout.rows =
405                         (screen_num_desktops + screen_num_desktops %
406                          screen_desktop_layout.columns) /
407                         screen_desktop_layout.columns;
408             }
409         }
410         g_free(data);
411     }
412 }
413
414 void screen_update_desktop_names()
415 {
416     guint i;
417
418     /* empty the array */
419     g_strfreev(screen_desktop_names);
420     screen_desktop_names = NULL;
421
422     if (PROP_GETSS(ob_root, net_desktop_names, utf8, &screen_desktop_names))
423         for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
424     else
425         i = 0;
426     if (i <= screen_num_desktops) {
427         screen_desktop_names = g_renew(char*, screen_desktop_names,
428                                        screen_num_desktops + 1);
429         screen_desktop_names[screen_num_desktops] = NULL;
430         for (; i < screen_num_desktops; ++i)
431             screen_desktop_names[i] = g_strdup("Unnamed Desktop");
432     }
433 }
434
435 void screen_show_desktop(gboolean show)
436 {
437     GList *it;
438      
439     if (show == screen_showing_desktop) return; /* no change */
440
441     screen_showing_desktop = show;
442
443     if (show) {
444         /* bottom to top */
445         for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
446             if (WINDOW_IS_CLIENT(it->data)) {
447                 Client *client = it->data;
448                 if (client->frame->visible && !client_should_show(client))
449                     frame_hide(client->frame);
450             }
451         }
452     } else {
453         /* top to bottom */
454         for (it = stacking_list; it != NULL; it = it->next) {
455             if (WINDOW_IS_CLIENT(it->data)) {
456                 Client *client = it->data;
457                 if (!client->frame->visible && client_should_show(client))
458                     frame_show(client->frame);
459             }
460         }
461     }
462
463     if (show) {
464         /* focus desktop */
465         for (it = focus_order[screen_desktop]; it; it = it->next)
466             if (((Client*)it->data)->type == Type_Desktop &&
467                 client_focus(it->data))
468                 break;
469     } else {
470         focus_fallback(Fallback_NoFocus);
471     }
472
473     show = !!show; /* make it boolean */
474     PROP_SET32(ob_root, net_showing_desktop, cardinal, show);
475
476     dispatch_ob(Event_Ob_ShowDesktop, show, 0);
477 }
478
479 void screen_install_colormap(Client *client, gboolean install)
480 {
481     XWindowAttributes wa;
482
483     if (client == NULL) {
484         if (install)
485             XInstallColormap(ob_display, render_colormap);
486         else
487             XUninstallColormap(ob_display, render_colormap);
488     } else {
489         if (XGetWindowAttributes(ob_display, client->window, &wa) &&
490             wa.colormap != None) {
491             xerror_set_ignore(TRUE);
492             if (install)
493                 XInstallColormap(ob_display, wa.colormap);
494             else
495                 XUninstallColormap(ob_display, wa.colormap);
496             xerror_set_ignore(FALSE);
497         }
498     }
499 }
500
501 void screen_update_struts()
502 {
503     GList *it;
504     guint i;
505      
506     g_free(strut);
507     strut = g_new0(Strut, screen_num_desktops + 1);
508
509     for (it = client_list; it != NULL; it = it->next) {
510         Client *c = it->data;
511         if (c->iconic) continue; /* these dont count in the strut */
512     
513         if (c->desktop == 0xffffffff) {
514             for (i = 0; i < screen_num_desktops; ++i)
515                 STRUT_ADD(strut[i], c->strut);
516         } else {
517             g_assert(c->desktop < screen_num_desktops);
518             STRUT_ADD(strut[c->desktop], c->strut);
519         }
520         /* apply to the 'all desktops' strut */
521         STRUT_ADD(strut[screen_num_desktops], c->strut);
522     }
523
524     for (i = 0; i < screen_num_desktops; ++i)
525         STRUT_ADD(strut[i], dock_strut);
526
527     screen_update_area();
528 }
529
530 static void screen_update_area()
531 {
532     guint i;
533     guint32 *dims;
534
535     g_free(area);
536     area = g_new0(Rect, screen_num_desktops + 1);
537      
538     dims = g_new(guint32, 4 * screen_num_desktops);
539     for (i = 0; i < screen_num_desktops + 1; ++i) {
540         Rect old_area = area[i];
541 /*
542   #ifdef    XINERAMA
543   // reset to the full areas
544   if (isXineramaActive())
545   xineramaUsableArea = getXineramaAreas();
546   #endif // XINERAMA
547 */
548
549         RECT_SET(area[i], strut[i].left, strut[i].top,
550                  screen_physical_size.width - (strut[i].left +
551                                                strut[i].right),
552                  screen_physical_size.height - (strut[i].top +
553                                                 strut[i].bottom));
554     
555 /*
556   #ifdef    XINERAMA
557   if (isXineramaActive()) {
558   // keep each of the ximerama-defined areas inside the strut
559   RectList::iterator xit, xend = xineramaUsableArea.end();
560   for (xit = xineramaUsableArea.begin(); xit != xend; ++xit) {
561   if (xit->x() < usableArea.x()) {
562   xit->setX(usableArea.x());
563   xit->setWidth(xit->width() - usableArea.x());
564   }
565   if (xit->y() < usableArea.y()) {
566   xit->setY(usableArea.y());
567   xit->setHeight(xit->height() - usableArea.y());
568   }
569   if (xit->x() + xit->width() > usableArea.width())
570   xit->setWidth(usableArea.width() - xit->x());
571   if (xit->y() + xit->height() > usableArea.height())
572   xit->setHeight(usableArea.height() - xit->y());
573   }
574   }
575   #endif // XINERAMA
576 */
577         if (!RECT_EQUAL(old_area, area[i])) {
578             /* the area has changed, adjust all the maximized windows */
579             GList *it;
580             for (it = client_list; it; it = it->next) {
581                 Client *c = it->data;
582                 if (i < screen_num_desktops) {
583                     if (c->desktop == i)
584                         client_remaximize(c);
585                 } else {
586                     /* the 'all desktops' size */
587                     if (c->desktop == DESKTOP_ALL)
588                         client_remaximize(c);
589                 }
590             }
591         }
592
593         /* don't set these for the 'all desktops' area */
594         if (i < screen_num_desktops) {
595             dims[(i * 4) + 0] = area[i].x;
596             dims[(i * 4) + 1] = area[i].y;
597             dims[(i * 4) + 2] = area[i].width;
598             dims[(i * 4) + 3] = area[i].height;
599         }
600     }
601     PROP_SETA32(ob_root, net_workarea, cardinal,
602                 dims, 4 * screen_num_desktops);
603     g_free(dims);
604 }
605
606 Rect *screen_area(guint desktop)
607 {
608     if (desktop >= screen_num_desktops) {
609         if (desktop == DESKTOP_ALL)
610             return &area[screen_num_desktops];
611         return NULL;
612     }
613     return &area[desktop];
614 }
615
616 Strut *screen_strut(guint desktop)
617 {
618     if (desktop >= screen_num_desktops) {
619         if (desktop == DESKTOP_ALL)
620             return &strut[screen_num_desktops];
621         return NULL;
622     }
623     return &strut[desktop];
624 }
625
626 static void set_root_cursor()
627 {
628 #ifdef USE_LIBSN
629         if (sn_busy_cnt)
630             XDefineCursor(ob_display, ob_root, ob_cursors.busy);
631         else
632 #endif
633             XDefineCursor(ob_display, ob_root, ob_cursors.ptr);
634 }
635
636 #ifdef USE_LIBSN
637 static void sn_timeout(void *data)
638 {
639     timer_stop(sn_timer);
640     sn_timer = NULL;
641     sn_busy_cnt = 0;
642
643     set_root_cursor();
644 }
645
646 static void sn_event_func(SnMonitorEvent *ev, void *data)
647 {
648     SnStartupSequence *seq;
649     const char *seq_id, *bin_name;
650     int cnt = sn_busy_cnt;
651
652     if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
653         return;
654
655     seq_id = sn_startup_sequence_get_id(seq);
656     bin_name = sn_startup_sequence_get_binary_name(seq);
657     
658     if (!(seq_id && bin_name))
659         return;
660
661     switch (sn_monitor_event_get_type(ev)) {
662     case SN_MONITOR_EVENT_INITIATED:
663         ++sn_busy_cnt;
664         if (sn_timer)
665             timer_stop(sn_timer);
666         /* 30 second timeout for apps to start */
667         sn_timer = timer_start(30 * 1000000, sn_timeout, NULL);
668         break;
669     case SN_MONITOR_EVENT_CHANGED:
670         break;
671     case SN_MONITOR_EVENT_COMPLETED:
672         if (sn_busy_cnt) --sn_busy_cnt;
673         if (sn_timer) {
674             timer_stop(sn_timer);
675             sn_timer = NULL;
676         }
677         break;
678     case SN_MONITOR_EVENT_CANCELED:
679         if (sn_busy_cnt) --sn_busy_cnt;
680         if (sn_timer) {
681             timer_stop(sn_timer);
682             sn_timer = NULL;
683         }
684     };
685
686     if (sn_busy_cnt != cnt)
687         set_root_cursor();
688 }
689 #endif