1 #include "startupnotify.h"
5 void sn_startup(gboolean reconfig) {}
6 void sn_shutdown(gboolean reconfig) {}
7 gboolean sn_app_starting() { return FALSE; }
8 void sn_app_started(gchar *wmclass) {}
9 gboolean sn_get_desktop(gchar *id, guint *desktop) { return FALSE; }
17 #define SN_API_NOT_YET_FROZEN
21 SnStartupSequence *seq;
25 static SnDisplay *sn_display;
26 static SnMonitorContext *sn_context;
27 static GSList *sn_waits; /* list of ObWaitDatas */
29 static ObWaitData* wait_data_new(SnStartupSequence *seq);
30 static void wait_data_free(ObWaitData *d);
31 static ObWaitData* wait_find(const gchar *id);
33 static void sn_handler(const XEvent *e, gpointer data);
34 static void sn_event_func(SnMonitorEvent *event, gpointer data);
36 void sn_startup(gboolean reconfig)
40 sn_display = sn_display_new(ob_display, NULL, NULL);
41 sn_context = sn_monitor_context_new(sn_display, ob_screen,
42 sn_event_func, NULL, NULL);
44 ob_main_loop_x_add(ob_main_loop, sn_handler, NULL, NULL);
47 void sn_shutdown(gboolean reconfig)
53 ob_main_loop_x_remove(ob_main_loop, sn_handler);
55 for (it = sn_waits; it; it = g_slist_next(it))
56 wait_data_free(it->data);
57 g_slist_free(sn_waits);
60 screen_set_root_cursor();
62 sn_monitor_context_unref(sn_context);
63 sn_display_unref(sn_display);
66 static ObWaitData* wait_data_new(SnStartupSequence *seq)
68 ObWaitData *d = g_new(ObWaitData, 1);
72 sn_startup_sequence_ref(d->seq);
77 static void wait_data_free(ObWaitData *d)
80 sn_startup_sequence_unref(d->seq);
86 static ObWaitData* wait_find(const gchar *id)
88 ObWaitData *ret = NULL;
91 for (it = sn_waits; it; it = g_slist_next(it)) {
92 ObWaitData *d = it->data;
93 if (!strcmp(id, sn_startup_sequence_get_id(d->seq))) {
101 gboolean sn_app_starting()
105 for (it = sn_waits; it; it = g_slist_next(it)) {
106 ObWaitData *d = it->data;
113 static gboolean sn_wait_timeout(gpointer data)
115 ObWaitData *d = data;
117 screen_set_root_cursor();
118 return FALSE; /* don't repeat */
121 static void sn_wait_destroy(gpointer data)
123 ObWaitData *d = data;
124 sn_waits = g_slist_remove(sn_waits, d);
128 static void sn_handler(const XEvent *e, gpointer data)
132 sn_display_process_event(sn_display, &ec);
135 static void sn_event_func(SnMonitorEvent *ev, gpointer data)
137 SnStartupSequence *seq;
138 gboolean change = FALSE;
141 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
144 switch (sn_monitor_event_get_type(ev)) {
145 case SN_MONITOR_EVENT_INITIATED:
146 d = wait_data_new(seq);
147 sn_waits = g_slist_prepend(sn_waits, d);
148 /* 30 second timeout for apps to start */
149 ob_main_loop_timeout_add(ob_main_loop, 30 * G_USEC_PER_SEC,
150 sn_wait_timeout, d, sn_wait_destroy);
153 case SN_MONITOR_EVENT_CHANGED:
154 /* XXX feedback changed? */
157 case SN_MONITOR_EVENT_COMPLETED:
158 case SN_MONITOR_EVENT_CANCELED:
159 if ((d = wait_find(sn_startup_sequence_get_id(seq)))) {
161 ob_main_loop_timeout_remove_data(ob_main_loop, sn_wait_timeout, d);
168 screen_set_root_cursor();
171 void sn_app_started(gchar *wmclass)
175 for (it = sn_waits; it; it = g_slist_next(it)) {
176 ObWaitData *d = it->data;
177 if (sn_startup_sequence_get_wmclass(d->seq) &&
178 !strcmp(sn_startup_sequence_get_wmclass(d->seq), wmclass))
180 sn_startup_sequence_complete(d->seq);
186 gboolean sn_get_desktop(gchar *id, guint *desktop)
190 if (id && (d = wait_find(id))) {
191 gint desk = sn_startup_sequence_get_workspace(d->seq);