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 for (it = sn_waits; it; it = g_slist_next(it))
54 wait_data_free(it->data);
55 g_slist_free(sn_waits);
58 screen_set_root_cursor();
60 sn_monitor_context_unref(sn_context);
61 sn_display_unref(sn_display);
64 static ObWaitData* wait_data_new(SnStartupSequence *seq)
66 ObWaitData *d = g_new(ObWaitData, 1);
70 sn_startup_sequence_ref(d->seq);
75 static void wait_data_free(ObWaitData *d)
78 sn_startup_sequence_unref(d->seq);
84 static ObWaitData* wait_find(const gchar *id)
86 ObWaitData *ret = NULL;
89 for (it = sn_waits; it; it = g_slist_next(it)) {
90 ObWaitData *d = it->data;
91 if (!strcmp(id, sn_startup_sequence_get_id(d->seq))) {
99 gboolean sn_app_starting()
103 for (it = sn_waits; it; it = g_slist_next(it)) {
104 ObWaitData *d = it->data;
111 static gboolean sn_wait_timeout(gpointer data)
113 ObWaitData *d = data;
115 screen_set_root_cursor();
116 return FALSE; /* don't repeat */
119 static void sn_wait_destroy(gpointer data)
121 ObWaitData *d = data;
122 sn_waits = g_slist_remove(sn_waits, d);
126 static void sn_handler(const XEvent *e, gpointer data)
130 sn_display_process_event(sn_display, &ec);
133 static void sn_event_func(SnMonitorEvent *ev, gpointer data)
135 SnStartupSequence *seq;
136 gboolean change = FALSE;
139 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
142 switch (sn_monitor_event_get_type(ev)) {
143 case SN_MONITOR_EVENT_INITIATED:
144 g_message("starting");
145 d = wait_data_new(seq);
146 sn_waits = g_slist_prepend(sn_waits, d);
147 /* 30 second timeout for apps to start */
148 ob_main_loop_timeout_add(ob_main_loop, 30 * G_USEC_PER_SEC,
149 sn_wait_timeout, d, sn_wait_destroy);
152 case SN_MONITOR_EVENT_CHANGED:
153 /* XXX feedback changed? */
156 case SN_MONITOR_EVENT_COMPLETED:
157 case SN_MONITOR_EVENT_CANCELED:
158 if ((d = wait_find(sn_startup_sequence_get_id(seq)))) {
160 ob_main_loop_timeout_remove_data(ob_main_loop, sn_wait_timeout, d);
167 screen_set_root_cursor();
170 void sn_app_started(gchar *wmclass)
174 for (it = sn_waits; it; it = g_slist_next(it)) {
175 ObWaitData *d = it->data;
176 if (sn_startup_sequence_get_wmclass(d->seq) &&
177 !strcmp(sn_startup_sequence_get_wmclass(d->seq), wmclass))
179 sn_startup_sequence_complete(d->seq);
185 gboolean sn_get_desktop(gchar *id, guint *desktop)
189 if (id && (d = wait_find(id))) {
190 gint desk = sn_startup_sequence_get_workspace(d->seq);