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