~muktupavels/metacity/adwaita-icon-theme-lp-1414613

« back to all changes in this revision

Viewing changes to src/wm-tester/main.c

  • Committer: Package Import Robot
  • Author(s): Dmitry Shachnev
  • Date: 2014-11-18 18:13:01 UTC
  • mto: (2.3.7 vivid-proposed)
  • mto: This revision was merged to the branch mainline in revision 135.
  • Revision ID: package-import@ubuntu.com-20141118181301-csmd2xaakfjv48r8
Tags: upstream-3.14.2
ImportĀ upstreamĀ versionĀ 3.14.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
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, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include <gtk/gtk.h>
21
 
 
22
 
#include <stdlib.h>
23
 
#include <sys/types.h>
24
 
#include <stdio.h>
25
 
#include <string.h>
26
 
#include <unistd.h>
27
 
 
28
 
static void set_up_the_evil (void);
29
 
static void set_up_icon_windows (void);
30
 
 
31
 
static void
32
 
usage (void)
33
 
{
34
 
  g_print ("wm-tester [--evil] [--icon-windows]\n");
35
 
  exit (0);
36
 
}
37
 
 
38
 
int
39
 
main (int argc, char **argv)
40
 
{
41
 
  int i;
42
 
  gboolean do_evil;
43
 
  gboolean do_icon_windows;
44
 
  
45
 
  gtk_init (&argc, &argv);  
46
 
  
47
 
  do_evil = FALSE;
48
 
  do_icon_windows = FALSE;
49
 
  
50
 
  i = 1;
51
 
  while (i < argc)
52
 
    {
53
 
      const char *arg = argv[i];
54
 
      
55
 
      if (strcmp (arg, "--help") == 0 ||
56
 
          strcmp (arg, "-h") == 0 ||
57
 
          strcmp (arg, "-?") == 0)
58
 
        usage ();
59
 
      else if (strcmp (arg, "--evil") == 0)
60
 
        do_evil = TRUE;
61
 
      else if (strcmp (arg, "--icon-windows") == 0)
62
 
        do_icon_windows = TRUE;
63
 
      else
64
 
        usage ();
65
 
      
66
 
      ++i;
67
 
    }
68
 
 
69
 
  /* Be sure some option was provided */
70
 
  if (! (do_evil || do_icon_windows))
71
 
    return 1;
72
 
  
73
 
  if (do_evil)
74
 
    set_up_the_evil ();
75
 
 
76
 
  if (do_icon_windows)
77
 
    set_up_icon_windows ();
78
 
  
79
 
  gtk_main ();
80
 
 
81
 
  return 0;
82
 
}
83
 
 
84
 
static GSList *evil_windows = NULL;
85
 
 
86
 
static gint
87
 
evil_timeout (gpointer data)
88
 
{
89
 
  int i;
90
 
  int n_windows;
91
 
  int len;
92
 
  int create_count;
93
 
  int destroy_count;
94
 
  
95
 
  len = g_slist_length (evil_windows);  
96
 
  
97
 
  if (len > 35)
98
 
    {
99
 
      create_count = 2;
100
 
      destroy_count = 5;
101
 
    }
102
 
  else
103
 
    {
104
 
      create_count = 5;
105
 
      destroy_count = 5;
106
 
    }
107
 
 
108
 
  /* Create some windows */
109
 
  n_windows = g_random_int_range (0, create_count);
110
 
  
111
 
  i = 0;
112
 
  while (i < n_windows)
113
 
    {
114
 
      GtkWidget *w;
115
 
      GtkWidget *c;
116
 
      int t;
117
 
      GtkWidget *parent;
118
 
      
119
 
      w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
120
 
 
121
 
      gtk_window_move (GTK_WINDOW (w),
122
 
                       g_random_int_range (0,
123
 
                                           gdk_screen_width ()),
124
 
                       g_random_int_range (0,
125
 
                                           gdk_screen_height ()));
126
 
 
127
 
      parent = NULL;
128
 
      
129
 
      /* set transient for random window (may create all kinds of weird cycles) */
130
 
      if (len > 0)
131
 
        {
132
 
          t = g_random_int_range (- (len / 3), len);
133
 
          if (t >= 0)
134
 
            {
135
 
              parent = g_slist_nth_data (evil_windows, t);
136
 
              
137
 
              if (parent != NULL)
138
 
                gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (parent));
139
 
            }
140
 
        }
141
 
      
142
 
      if (parent != NULL)
143
 
        c = gtk_button_new_with_label ("Evil Transient!");
144
 
      else
145
 
        c = gtk_button_new_with_label ("Evil Window!");
146
 
      gtk_container_add (GTK_CONTAINER (w), c);
147
 
      
148
 
      gtk_widget_show_all (w);
149
 
      
150
 
      evil_windows = g_slist_prepend (evil_windows, w);
151
 
      
152
 
      ++i;
153
 
    }
154
 
 
155
 
  /* Destroy some windows */
156
 
  if (len > destroy_count)
157
 
    {
158
 
      n_windows = g_random_int_range (0, destroy_count);
159
 
      i = 0;
160
 
      while (i < n_windows)
161
 
        {
162
 
          GtkWidget *w;
163
 
          
164
 
          w = g_slist_nth_data (evil_windows,
165
 
                                g_random_int_range (0, len));
166
 
          if (w)
167
 
            {
168
 
              --len;
169
 
              evil_windows = g_slist_remove (evil_windows, w);
170
 
              gtk_widget_destroy (w);
171
 
            }
172
 
          
173
 
          ++i;
174
 
        }
175
 
    }
176
 
  
177
 
  return TRUE;
178
 
}
179
 
 
180
 
static void
181
 
set_up_the_evil (void)
182
 
{
183
 
  g_timeout_add (400, evil_timeout, NULL);
184
 
}
185
 
 
186
 
static void
187
 
set_up_icon_windows (void)
188
 
{
189
 
  int i;
190
 
  int n_windows;
191
 
 
192
 
  /* Create some windows */
193
 
  n_windows = 9;
194
 
  
195
 
  i = 0;
196
 
  while (i < n_windows)
197
 
    {
198
 
      GtkWidget *w;
199
 
      GtkWidget *c;
200
 
      GList *icons;
201
 
      GdkPixbuf *pix;
202
 
      int size  = 0;
203
 
      
204
 
      w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
205
 
      c = gtk_button_new_with_label ("Icon window");
206
 
      gtk_container_add (GTK_CONTAINER (w), c);
207
 
 
208
 
      icons = NULL;
209
 
 
210
 
      gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, NULL, &size);
211
 
      pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "gtk-save", size, 0, NULL);
212
 
      
213
 
      icons = g_list_append (icons, pix);
214
 
 
215
 
      if (i % 2)
216
 
        {
217
 
          gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, NULL, &size);
218
 
          pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "gtk-save", size, 0, NULL);
219
 
          icons = g_list_append (icons, pix);
220
 
        }
221
 
 
222
 
      if (i % 3)
223
 
        {
224
 
          gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, NULL, &size);
225
 
          pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "gtk-save", size, 0, NULL);
226
 
          icons = g_list_append (icons, pix);
227
 
        }
228
 
 
229
 
      gtk_window_set_icon_list (GTK_WINDOW (w), icons);
230
 
 
231
 
      g_list_foreach (icons, (GFunc) g_object_unref, NULL);
232
 
      g_list_free (icons);
233
 
      
234
 
      gtk_widget_show_all (w);
235
 
      
236
 
      ++i;
237
 
    }
238
 
}