Merge lp:~agateau/notify-osd/no-bubble-in-fullscreen into lp:notify-osd/trunk

Proposed by Aurélien Gâteau
Status: Merged
Merged at revision: not available
Proposed branch: lp:~agateau/notify-osd/no-bubble-in-fullscreen
Merge into: lp:notify-osd/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~agateau/notify-osd/no-bubble-in-fullscreen
Reviewer Review Type Date Requested Status
David Barth (community) Approve
Review via email: mp+7192@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aurélien Gâteau (agateau) wrote :

Do not show notifications if a fullscreen application is running on the default screen.

Revision history for this message
David Barth (dbarth) wrote :

The fix comes with a test. Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2009-04-16 14:02:12 +0000
3+++ src/Makefile.am 2009-06-02 16:28:26 +0000
4@@ -80,6 +80,7 @@
5 $(GLIB_CFLAGS) \
6 $(GCONF_CFLAGS) \
7 $(DBUS_CFLAGS) \
8+ -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
9 $(WNCK_CFLAGS) \
10 $(NULL)
11
12
13=== modified file 'src/dnd.c'
14--- src/dnd.c 2009-05-15 08:17:36 +0000
15+++ src/dnd.c 2009-06-03 09:18:29 +0000
16@@ -40,6 +40,8 @@
17 #include <X11/Xatom.h>
18 #include <gdk/gdkx.h>
19
20+#include <libwnck/libwnck.h>
21+
22 #include "dbus.h"
23
24 static DBusGProxy *gsmgr = NULL;
25@@ -167,6 +169,29 @@
26 return FALSE;
27 }
28
29+static int
30+is_fullscreen_cb (WnckWindow *window, WnckWorkspace *workspace)
31+{
32+ if (wnck_window_is_visible_on_workspace (window, workspace)
33+ && wnck_window_is_fullscreen (window))
34+ {
35+ return 0;
36+ } else {
37+ return 1;
38+ }
39+}
40+
41+gboolean
42+dnd_has_one_fullscreen_window (void)
43+{
44+ WnckScreen *screen = wnck_screen_get_default ();
45+ wnck_screen_force_update (screen);
46+ WnckWorkspace *workspace = wnck_screen_get_active_workspace (screen);
47+ GList *list = wnck_screen_get_windows (screen);
48+ GList *item = g_list_find_custom (list, workspace, (GCompareFunc) is_fullscreen_cb);
49+ return item != NULL;
50+}
51+
52 /* Tries to determine whether the user is in "do not disturb" mode */
53 gboolean
54 dnd_dont_disturb_user (void)
55@@ -175,5 +200,6 @@
56 || dnd_is_xscreensaver_active()
57 || dnd_is_screensaver_active()
58 || dnd_is_screensaver_inhibited()
59+ || dnd_has_one_fullscreen_window()
60 );
61 }
62
63=== modified file 'src/dnd.h'
64--- src/dnd.h 2009-03-19 10:53:20 +0000
65+++ src/dnd.h 2009-06-02 16:28:26 +0000
66@@ -44,6 +44,8 @@
67 gboolean
68 dnd_is_screensaver_active (void);
69
70+gboolean
71+dnd_has_one_fullscreen_window (void);
72
73 G_END_DECLS
74
75
76=== modified file 'tests/Makefile.am'
77--- tests/Makefile.am 2009-05-15 08:27:09 +0000
78+++ tests/Makefile.am 2009-06-02 16:28:26 +0000
79@@ -43,6 +43,7 @@
80 -Wall -Werror -std=c99 \
81 $(GLIB_CFLAGS) \
82 $(GTK_CFLAGS) \
83+ -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
84 $(WNCK_CFLAGS) \
85 $(DBUS_CFLAGS) \
86 -I$(top_srcdir)/src
87
88=== modified file 'tests/test-dnd.c'
89--- tests/test-dnd.c 2009-03-19 14:52:08 +0000
90+++ tests/test-dnd.c 2009-06-03 09:18:29 +0000
91@@ -32,6 +32,8 @@
92
93 #include "dnd.h"
94
95+#include <libwnck/libwnck.h>
96+
97 #define TEST_DBUS_NAME "org.freedesktop.Notificationstest"
98
99 static
100@@ -49,20 +51,77 @@
101 g_debug ("screensaver is active");
102 }
103
104+static
105+gboolean
106+check_fullscreen (GMainLoop *loop)
107+{
108+ g_assert (dnd_has_one_fullscreen_window());
109+ g_main_loop_quit (loop);
110+ return FALSE;
111+}
112+
113+static
114+gboolean
115+check_no_fullscreen (GMainLoop *loop)
116+{
117+ g_assert (!dnd_has_one_fullscreen_window());
118+ g_main_loop_quit (loop);
119+ return FALSE;
120+}
121+
122+static
123+WnckWorkspace *
124+find_free_workspace (WnckScreen *screen)
125+{
126+ WnckWorkspace *active_workspace = wnck_screen_get_active_workspace (screen);
127+ GList *lst = wnck_screen_get_workspaces (screen);
128+
129+ if (lst->data != active_workspace) {
130+ return WNCK_WORKSPACE(lst->data);
131+ }
132+ lst = g_list_next (lst);
133+ g_assert (lst);
134+ return WNCK_WORKSPACE(lst->data);
135+}
136+
137+static
138+void
139+test_dnd_fullscreen (void)
140+{
141+ g_assert (!dnd_has_one_fullscreen_window());
142+
143+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
144+ gtk_window_fullscreen (GTK_WINDOW (window));
145+ gtk_widget_show_now (window);
146+
147+ GMainLoop* loop = g_main_loop_new (NULL, FALSE);
148+ g_timeout_add (2000, (GSourceFunc) check_fullscreen, loop);
149+ g_main_loop_run (loop);
150+
151+ // Move window to a free workspace, dnd_has_one_fullscreen_window should
152+ // not find it anymore
153+ WnckScreen *screen = wnck_screen_get_default ();
154+ WnckWindow *wnck_window = wnck_screen_get_active_window (screen);
155+ g_assert (wnck_window);
156+ WnckWorkspace *free_workspace = find_free_workspace (screen);
157+ g_assert (free_workspace);
158+ wnck_window_move_to_workspace (wnck_window, free_workspace);
159+
160+ g_timeout_add (2000, (GSourceFunc) check_no_fullscreen, loop);
161+ g_main_loop_run (loop);
162+
163+ gtk_widget_destroy (window);
164+}
165+
166 GTestSuite *
167 test_dnd_create_test_suite (void)
168 {
169 GTestSuite *ts = NULL;
170- GTestCase *tc = NULL;
171
172 ts = g_test_create_suite ("dnd");
173- tc = g_test_create_case ("detect screensaver",
174- 0,
175- NULL,
176- NULL,
177- test_dnd_screensaver,
178- NULL);
179- g_test_suite_add (ts, tc);
180+#define TC(x) g_test_create_case(#x, 0, NULL, NULL, x, NULL)
181+ g_test_suite_add (ts, TC(test_dnd_screensaver));
182+ g_test_suite_add (ts, TC(test_dnd_fullscreen));
183
184 return ts;
185 }

Subscribers

People subscribed via source and target branches