more namespacing with Rr*
[mikachu/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     g_message("switch fallback");
340     focus_fallback(Fallback_Desktop);
341     g_message("/switch fallback");
342
343     dispatch_ob(Event_Ob_Desktop, num, old);
344 }
345
346 void screen_update_layout()
347 {
348     guint32 *data = NULL;
349     guint num;
350
351     /* defaults */
352     screen_desktop_layout.orientation = prop_atoms.net_wm_orientation_horz;
353     screen_desktop_layout.start_corner = prop_atoms.net_wm_topleft;
354     screen_desktop_layout.rows = 1;
355     screen_desktop_layout.columns = screen_num_desktops;
356
357     if (PROP_GETA32(ob_root, net_desktop_layout, cardinal, &data, &num)) {
358         if (num == 3 || num == 4) {
359             if (data[0] == prop_atoms.net_wm_orientation_vert)
360                 screen_desktop_layout.orientation = data[0];
361             if (num == 3)
362                 screen_desktop_layout.start_corner =
363                     prop_atoms.net_wm_topright;
364             else {
365                 if (data[3] == prop_atoms.net_wm_topright)
366                     screen_desktop_layout.start_corner = data[3];
367                 else if (data[3] == prop_atoms.net_wm_bottomright)
368                     screen_desktop_layout.start_corner = data[3];
369                 else if (data[3] == prop_atoms.net_wm_bottomleft)
370                     screen_desktop_layout.start_corner = data[3];
371             }
372
373             /* fill in a zero rows/columns */
374             if (!(data[1] == 0 && data[2] == 0)) { /* both 0's is bad data.. */
375                 if (data[1] == 0) {
376                     data[1] = (screen_num_desktops +
377                                screen_num_desktops % data[2]) / data[2];
378                 } else if (data[2] == 0) {
379                     data[2] = (screen_num_desktops +
380                                screen_num_desktops % data[1]) / data[1];
381                 }
382                 screen_desktop_layout.columns = data[1];
383                 screen_desktop_layout.rows = data[2];
384             }
385
386             /* bounds checking */
387             if (screen_desktop_layout.orientation ==
388                 prop_atoms.net_wm_orientation_horz) {
389                 if (screen_desktop_layout.rows > screen_num_desktops)
390                     screen_desktop_layout.rows = screen_num_desktops;
391                 if (screen_desktop_layout.columns >
392                     ((screen_num_desktops + screen_num_desktops %
393                       screen_desktop_layout.rows) /
394                      screen_desktop_layout.rows))
395                     screen_desktop_layout.columns =
396                         (screen_num_desktops + screen_num_desktops %
397                          screen_desktop_layout.rows) /
398                         screen_desktop_layout.rows;
399             } else {
400                 if (screen_desktop_layout.columns > screen_num_desktops)
401                     screen_desktop_layout.columns = screen_num_desktops;
402                 if (screen_desktop_layout.rows >
403                     ((screen_num_desktops + screen_num_desktops %
404                       screen_desktop_layout.columns) /
405                      screen_desktop_layout.columns))
406                     screen_desktop_layout.rows =
407                         (screen_num_desktops + screen_num_desktops %
408                          screen_desktop_layout.columns) /
409                         screen_desktop_layout.columns;
410             }
411         }
412         g_free(data);
413     }
414 }
415
416 void screen_update_desktop_names()
417 {
418     guint i;
419
420     /* empty the array */
421     g_strfreev(screen_desktop_names);
422     screen_desktop_names = NULL;
423
424     if (PROP_GETSS(ob_root, net_desktop_names, utf8, &screen_desktop_names))
425         for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
426     else
427         i = 0;
428     if (i <= screen_num_desktops) {
429         screen_desktop_names = g_renew(char*, screen_desktop_names,
430                                        screen_num_desktops + 1);
431         screen_desktop_names[screen_num_desktops] = NULL;
432         for (; i < screen_num_desktops; ++i)
433             screen_desktop_names[i] = g_strdup("Unnamed Desktop");
434     }
435 }
436
437 void screen_show_desktop(gboolean show)
438 {
439     GList *it;
440      
441     if (show == screen_showing_desktop) return; /* no change */
442
443     screen_showing_desktop = show;
444
445     if (show) {
446         /* bottom to top */
447         for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
448             if (WINDOW_IS_CLIENT(it->data)) {
449                 Client *client = it->data;
450                 if (client->frame->visible && !client_should_show(client))
451                     frame_hide(client->frame);
452             }
453         }
454     } else {
455         /* top to bottom */
456         for (it = stacking_list; it != NULL; it = it->next) {
457             if (WINDOW_IS_CLIENT(it->data)) {
458                 Client *client = it->data;
459                 if (!client->frame->visible && client_should_show(client))
460                     frame_show(client->frame);
461             }
462         }
463     }
464
465     if (show) {
466         /* focus desktop */
467         for (it = focus_order[screen_desktop]; it; it = it->next)
468             if (((Client*)it->data)->type == Type_Desktop &&
469                 client_focus(it->data))
470                 break;
471     } else {
472         focus_fallback(Fallback_NoFocus);
473     }
474
475     show = !!show; /* make it boolean */
476     PROP_SET32(ob_root, net_showing_desktop, cardinal, show);
477
478     dispatch_ob(Event_Ob_ShowDesktop, show, 0);
479 }
480
481 void screen_install_colormap(Client *client, gboolean install)
482 {
483     XWindowAttributes wa;
484
485     if (client == NULL) {
486         if (install)
487             XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
488         else
489             XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
490     } else {
491         if (XGetWindowAttributes(ob_display, client->window, &wa) &&
492             wa.colormap != None) {
493             xerror_set_ignore(TRUE);
494             if (install)
495                 XInstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
496             else
497                 XUninstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
498             xerror_set_ignore(FALSE);
499         }
500     }
501 }
502
503 void screen_update_struts()
504 {
505     GList *it;
506     guint i;
507      
508     g_free(strut);
509     strut = g_new0(Strut, screen_num_desktops + 1);
510
511     for (it = client_list; it != NULL; it = it->next) {
512         Client *c = it->data;
513         if (c->iconic) continue; /* these dont count in the strut */
514     
515         if (c->desktop == 0xffffffff) {
516             for (i = 0; i < screen_num_desktops; ++i)
517                 STRUT_ADD(strut[i], c->strut);
518         } else {
519             g_assert(c->desktop < screen_num_desktops);
520             STRUT_ADD(strut[c->desktop], c->strut);
521         }
522         /* apply to the 'all desktops' strut */
523         STRUT_ADD(strut[screen_num_desktops], c->strut);
524     }
525
526     for (i = 0; i < screen_num_desktops; ++i)
527         STRUT_ADD(strut[i], dock_strut);
528
529     screen_update_area();
530 }
531
532 static void screen_update_area()
533 {
534     guint i;
535     guint32 *dims;
536
537     g_free(area);
538     area = g_new0(Rect, screen_num_desktops + 1);
539      
540     dims = g_new(guint32, 4 * screen_num_desktops);
541     for (i = 0; i < screen_num_desktops + 1; ++i) {
542         Rect old_area = area[i];
543 /*
544   #ifdef    XINERAMA
545   // reset to the full areas
546   if (isXineramaActive())
547   xineramaUsableArea = getXineramaAreas();
548   #endif // XINERAMA
549 */
550
551         RECT_SET(area[i], strut[i].left, strut[i].top,
552                  screen_physical_size.width - (strut[i].left +
553                                                strut[i].right),
554                  screen_physical_size.height - (strut[i].top +
555                                                 strut[i].bottom));
556     
557 /*
558   #ifdef    XINERAMA
559   if (isXineramaActive()) {
560   // keep each of the ximerama-defined areas inside the strut
561   RectList::iterator xit, xend = xineramaUsableArea.end();
562   for (xit = xineramaUsableArea.begin(); xit != xend; ++xit) {
563   if (xit->x() < usableArea.x()) {
564   xit->setX(usableArea.x());
565   xit->setWidth(xit->width() - usableArea.x());
566   }
567   if (xit->y() < usableArea.y()) {
568   xit->setY(usableArea.y());
569   xit->setHeight(xit->height() - usableArea.y());
570   }
571   if (xit->x() + xit->width() > usableArea.width())
572   xit->setWidth(usableArea.width() - xit->x());
573   if (xit->y() + xit->height() > usableArea.height())
574   xit->setHeight(usableArea.height() - xit->y());
575   }
576   }
577   #endif // XINERAMA
578 */
579         if (!RECT_EQUAL(old_area, area[i])) {
580             /* the area has changed, adjust all the maximized windows */
581             GList *it;
582             for (it = client_list; it; it = it->next) {
583                 Client *c = it->data;
584                 if (i < screen_num_desktops) {
585                     if (c->desktop == i)
586                         client_reconfigure(c);
587                 } else {
588                     /* the 'all desktops' size */
589                     if (c->desktop == DESKTOP_ALL)
590                         client_reconfigure(c);
591                 }
592             }
593         }
594
595         /* don't set these for the 'all desktops' area */
596         if (i < screen_num_desktops) {
597             dims[(i * 4) + 0] = area[i].x;
598             dims[(i * 4) + 1] = area[i].y;
599             dims[(i * 4) + 2] = area[i].width;
600             dims[(i * 4) + 3] = area[i].height;
601         }
602     }
603     PROP_SETA32(ob_root, net_workarea, cardinal,
604                 dims, 4 * screen_num_desktops);
605     g_free(dims);
606 }
607
608 Rect *screen_area(guint desktop)
609 {
610     if (desktop >= screen_num_desktops) {
611         if (desktop == DESKTOP_ALL)
612             return &area[screen_num_desktops];
613         return NULL;
614     }
615     return &area[desktop];
616 }
617
618 Strut *screen_strut(guint desktop)
619 {
620     if (desktop >= screen_num_desktops) {
621         if (desktop == DESKTOP_ALL)
622             return &strut[screen_num_desktops];
623         return NULL;
624     }
625     return &strut[desktop];
626 }
627
628 static void set_root_cursor()
629 {
630 #ifdef USE_LIBSN
631         if (sn_busy_cnt)
632             XDefineCursor(ob_display, ob_root, ob_cursors.busy);
633         else
634 #endif
635             XDefineCursor(ob_display, ob_root, ob_cursors.ptr);
636 }
637
638 #ifdef USE_LIBSN
639 static void sn_timeout(void *data)
640 {
641     timer_stop(sn_timer);
642     sn_timer = NULL;
643     sn_busy_cnt = 0;
644
645     set_root_cursor();
646 }
647
648 static void sn_event_func(SnMonitorEvent *ev, void *data)
649 {
650     SnStartupSequence *seq;
651     const char *seq_id, *bin_name;
652     int cnt = sn_busy_cnt;
653
654     if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
655         return;
656
657     seq_id = sn_startup_sequence_get_id(seq);
658     bin_name = sn_startup_sequence_get_binary_name(seq);
659     
660     if (!(seq_id && bin_name))
661         return;
662
663     switch (sn_monitor_event_get_type(ev)) {
664     case SN_MONITOR_EVENT_INITIATED:
665         ++sn_busy_cnt;
666         if (sn_timer)
667             timer_stop(sn_timer);
668         /* 30 second timeout for apps to start */
669         sn_timer = timer_start(30 * 1000000, sn_timeout, NULL);
670         break;
671     case SN_MONITOR_EVENT_CHANGED:
672         break;
673     case SN_MONITOR_EVENT_COMPLETED:
674         if (sn_busy_cnt) --sn_busy_cnt;
675         if (sn_timer) {
676             timer_stop(sn_timer);
677             sn_timer = NULL;
678         }
679         break;
680     case SN_MONITOR_EVENT_CANCELED:
681         if (sn_busy_cnt) --sn_busy_cnt;
682         if (sn_timer) {
683             timer_stop(sn_timer);
684             sn_timer = NULL;
685         }
686     };
687
688     if (sn_busy_cnt != cnt)
689         set_root_cursor();
690 }
691 #endif