1 /* WM tester main() */
2
3 /*
4 * Copyright (C) 2001 Havoc Pennington
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street - Suite 500, Boston, MA
19 * 02110-1335, USA.
20 */
21
22 #include <gtk/gtk.h>
23
24 #include <stdlib.h>
25 #include <sys/types.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <unistd.h>
29
30 static void set_up_the_evil (void);
31 static void set_up_icon_windows (void);
32
33 static void
usage(void)34 usage (void)
35 {
36 g_print ("wm-tester [--evil] [--icon-windows]\n");
37 exit (0);
38 }
39
40 int
main(int argc,char ** argv)41 main (int argc, char **argv)
42 {
43 int i;
44 gboolean do_evil;
45 gboolean do_icon_windows;
46
47 gtk_init (&argc, &argv);
48
49 do_evil = FALSE;
50 do_icon_windows = FALSE;
51
52 i = 1;
53 while (i < argc)
54 {
55 const char *arg = argv[i];
56
57 if (strcmp (arg, "--help") == 0 ||
58 strcmp (arg, "-h") == 0 ||
59 strcmp (arg, "-?") == 0)
60 usage ();
61 else if (strcmp (arg, "--evil") == 0)
62 do_evil = TRUE;
63 else if (strcmp (arg, "--icon-windows") == 0)
64 do_icon_windows = TRUE;
65 else
66 usage ();
67
68 ++i;
69 }
70
71 /* Be sure some option was provided */
72 if (! (do_evil || do_icon_windows))
73 return 1;
74
75 if (do_evil)
76 set_up_the_evil ();
77
78 if (do_icon_windows)
79 set_up_icon_windows ();
80
81 gtk_main ();
82
83 return 0;
84 }
85
86 static GSList *evil_windows = NULL;
87
88 static gint
evil_timeout(gpointer data)89 evil_timeout (gpointer data)
90 {
91 int i;
92 int n_windows;
93 int len;
94 int create_count;
95 int destroy_count;
96
97 len = g_slist_length (evil_windows);
98
99 if (len > 35)
100 {
101 create_count = 2;
102 destroy_count = 5;
103 }
104 else
105 {
106 create_count = 5;
107 destroy_count = 5;
108 }
109
110 /* Create some windows */
111 n_windows = g_random_int_range (0, create_count);
112
113 i = 0;
114 while (i < n_windows)
115 {
116 GtkWidget *w;
117 GtkWidget *c;
118 int t;
119 GtkWidget *parent;
120
121 w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
122
123 gtk_window_move (GTK_WINDOW (w),
124 g_random_int_range (0,
125 gdk_screen_width ()),
126 g_random_int_range (0,
127 gdk_screen_height ()));
128
129 parent = NULL;
130
131 /* set transient for random window (may create all kinds of weird cycles) */
132 if (len > 0)
133 {
134 t = g_random_int_range (- (len / 3), len);
135 if (t >= 0)
136 {
137 parent = g_slist_nth_data (evil_windows, t);
138
139 if (parent != NULL)
140 gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (parent));
141 }
142 }
143
144 if (parent != NULL)
145 c = gtk_button_new_with_label ("Evil Transient!");
146 else
147 c = gtk_button_new_with_label ("Evil Window!");
148 gtk_container_add (GTK_CONTAINER (w), c);
149
150 gtk_widget_show_all (w);
151
152 evil_windows = g_slist_prepend (evil_windows, w);
153
154 ++i;
155 }
156
157 /* Destroy some windows */
158 if (len > destroy_count)
159 {
160 n_windows = g_random_int_range (0, destroy_count);
161 i = 0;
162 while (i < n_windows)
163 {
164 GtkWidget *w;
165
166 w = g_slist_nth_data (evil_windows,
167 g_random_int_range (0, len));
168 if (w)
169 {
170 --len;
171 evil_windows = g_slist_remove (evil_windows, w);
172 gtk_widget_destroy (w);
173 }
174
175 ++i;
176 }
177 }
178
179 return TRUE;
180 }
181
182 static void
set_up_the_evil(void)183 set_up_the_evil (void)
184 {
185 g_timeout_add (400, evil_timeout, NULL);
186 }
187
188 static void
set_up_icon_windows(void)189 set_up_icon_windows (void)
190 {
191 int i;
192 int n_windows;
193
194 /* Create some windows */
195 n_windows = 9;
196
197 i = 0;
198 while (i < n_windows)
199 {
200 GtkWidget *w;
201 GtkWidget *c;
202 GList *icons;
203 GtkIconTheme *theme;
204 GdkPixbuf *pix;
205
206 w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
207 c = gtk_button_new_with_label ("Icon window");
208 gtk_container_add (GTK_CONTAINER (w), c);
209
210 theme = gtk_icon_theme_get_default ();
211
212 icons = NULL;
213
214 pix = gtk_icon_theme_load_icon (theme,
215 "document-save",
216 24,
217 0,
218 NULL);
219
220 icons = g_list_append (icons, pix);
221
222 if (i % 2)
223 {
224 pix = gtk_icon_theme_load_icon (theme,
225 "document-save",
226 48,
227 0,
228 NULL);
229 icons = g_list_append (icons, pix);
230 }
231
232 if (i % 3)
233 {
234 pix = gtk_icon_theme_load_icon (theme,
235 "document-save",
236 16,
237 0,
238 NULL);
239 icons = g_list_append (icons, pix);
240 }
241
242 gtk_window_set_icon_list (GTK_WINDOW (w), icons);
243
244 g_list_foreach (icons, (GFunc) g_object_unref, NULL);
245 g_list_free (icons);
246
247 gtk_widget_show_all (w);
248
249 ++i;
250 }
251 }
252