]> Dogcows Code - chaz/openbox/blob - openbox/startupnotify.c
add the _NET_WM_USER_TIME property support. When focus_new is enabled, don't focus...
[chaz/openbox] / openbox / startupnotify.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 startupnotify.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "startupnotify.h"
21
22 #ifndef USE_LIBSN
23
24 void sn_startup(gboolean reconfig) {}
25 void sn_shutdown(gboolean reconfig) {}
26 gboolean sn_app_starting() { return FALSE; }
27 Time sn_app_started(const gchar *id, const gchar *wmclass)
28 {
29 return CurrentTime;
30 }
31 gboolean sn_get_desktop(gchar *id, guint *desktop) { return FALSE; }
32
33 #else
34
35 #include "openbox.h"
36 #include "mainloop.h"
37 #include "screen.h"
38
39 #define SN_API_NOT_YET_FROZEN
40 #include <libsn/sn.h>
41
42 typedef struct {
43 SnStartupSequence *seq;
44 gboolean feedback;
45 } ObWaitData;
46
47 static SnDisplay *sn_display;
48 static SnMonitorContext *sn_context;
49 static GSList *sn_waits; /* list of ObWaitDatas */
50
51 static ObWaitData* wait_data_new(SnStartupSequence *seq);
52 static void wait_data_free(ObWaitData *d);
53 static ObWaitData* wait_find(const gchar *id);
54
55 static void sn_handler(const XEvent *e, gpointer data);
56 static void sn_event_func(SnMonitorEvent *event, gpointer data);
57
58 void sn_startup(gboolean reconfig)
59 {
60 if (reconfig) return;
61
62 sn_display = sn_display_new(ob_display, NULL, NULL);
63 sn_context = sn_monitor_context_new(sn_display, ob_screen,
64 sn_event_func, NULL, NULL);
65
66 ob_main_loop_x_add(ob_main_loop, sn_handler, NULL, NULL);
67 }
68
69 void sn_shutdown(gboolean reconfig)
70 {
71 GSList *it;
72
73 if (reconfig) return;
74
75 ob_main_loop_x_remove(ob_main_loop, sn_handler);
76
77 for (it = sn_waits; it; it = g_slist_next(it))
78 wait_data_free(it->data);
79 g_slist_free(sn_waits);
80 sn_waits = NULL;
81
82 screen_set_root_cursor();
83
84 sn_monitor_context_unref(sn_context);
85 sn_display_unref(sn_display);
86 }
87
88 static ObWaitData* wait_data_new(SnStartupSequence *seq)
89 {
90 ObWaitData *d = g_new(ObWaitData, 1);
91 d->seq = seq;
92 d->feedback = TRUE;
93
94 sn_startup_sequence_ref(d->seq);
95
96 return d;
97 }
98
99 static void wait_data_free(ObWaitData *d)
100 {
101 if (d) {
102 sn_startup_sequence_unref(d->seq);
103
104 g_free(d);
105 }
106 }
107
108 static ObWaitData* wait_find(const gchar *id)
109 {
110 ObWaitData *ret = NULL;
111 GSList *it;
112
113 for (it = sn_waits; it; it = g_slist_next(it)) {
114 ObWaitData *d = it->data;
115 if (!strcmp(id, sn_startup_sequence_get_id(d->seq))) {
116 ret = d;
117 break;
118 }
119 }
120 return ret;
121 }
122
123 gboolean sn_app_starting()
124 {
125 GSList *it;
126
127 for (it = sn_waits; it; it = g_slist_next(it)) {
128 ObWaitData *d = it->data;
129 if (d->feedback)
130 return TRUE;
131 }
132 return FALSE;
133 }
134
135 static gboolean sn_wait_timeout(gpointer data)
136 {
137 ObWaitData *d = data;
138 d->feedback = FALSE;
139 screen_set_root_cursor();
140 return FALSE; /* don't repeat */
141 }
142
143 static void sn_wait_destroy(gpointer data)
144 {
145 ObWaitData *d = data;
146 sn_waits = g_slist_remove(sn_waits, d);
147 wait_data_free(d);
148 }
149
150 static void sn_handler(const XEvent *e, gpointer data)
151 {
152 XEvent ec;
153 ec = *e;
154 sn_display_process_event(sn_display, &ec);
155 }
156
157 static void sn_event_func(SnMonitorEvent *ev, gpointer data)
158 {
159 SnStartupSequence *seq;
160 gboolean change = FALSE;
161 ObWaitData *d;
162
163 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
164 return;
165
166 switch (sn_monitor_event_get_type(ev)) {
167 case SN_MONITOR_EVENT_INITIATED:
168 d = wait_data_new(seq);
169 sn_waits = g_slist_prepend(sn_waits, d);
170 /* 15 second timeout for apps to start */
171 ob_main_loop_timeout_add(ob_main_loop, 15 * G_USEC_PER_SEC,
172 sn_wait_timeout, d, sn_wait_destroy);
173 change = TRUE;
174 break;
175 case SN_MONITOR_EVENT_CHANGED:
176 /* XXX feedback changed? */
177 change = TRUE;
178 break;
179 case SN_MONITOR_EVENT_COMPLETED:
180 case SN_MONITOR_EVENT_CANCELED:
181 if ((d = wait_find(sn_startup_sequence_get_id(seq)))) {
182 d->feedback = FALSE;
183 ob_main_loop_timeout_remove_data(ob_main_loop, sn_wait_timeout,
184 d, FALSE);
185 change = TRUE;
186 }
187 break;
188 };
189
190 if (change)
191 screen_set_root_cursor();
192 }
193
194 Time sn_app_started(const gchar *id, const gchar *wmclass)
195 {
196 GSList *it;
197 Time t = CurrentTime;
198
199 for (it = sn_waits; it; it = g_slist_next(it)) {
200 ObWaitData *d = it->data;
201 const gchar *seqid, *seqclass;
202 seqid = sn_startup_sequence_get_id(d->seq);
203 seqclass = sn_startup_sequence_get_wmclass(d->seq);
204 if ((seqid && id && !strcmp(seqid, id)) ||
205 (seqclass && wmclass && !strcmp(seqclass, wmclass)))
206 {
207 sn_startup_sequence_complete(d->seq);
208 t = sn_startup_sequence_get_timestamp(d->seq);
209 break;
210 }
211 }
212 return t;
213 }
214
215 gboolean sn_get_desktop(gchar *id, guint *desktop)
216 {
217 ObWaitData *d;
218
219 if (id && (d = wait_find(id))) {
220 gint desk = sn_startup_sequence_get_workspace(d->seq);
221 if (desk != -1) {
222 *desktop = desk;
223 return TRUE;
224 }
225 }
226 return FALSE;
227 }
228
229 #endif
This page took 0.044769 seconds and 5 git commands to generate.