~ubuntu-branches/ubuntu/wily/alltray/wily

« back to all changes in this revision

Viewing changes to src/parent.c

  • Committer: Bazaar Package Importer
  • Author(s): Ignace Mouzannar
  • Date: 2010-11-20 16:16:12 UTC
  • mfrom: (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20101120161612-12y0wqt6g86fb7hu
Tags: 0.71b-1
* New upstream release. (Closes: #602233)
  - Fixes no windows hiding when using compiz. (Closes: #579503)
* debian/control:
  - Bumped Standards-Version to 3.9.1.
* debian/patches:
  - Removed 01_minor_type.diff as it has been integrated upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 *
23
23
 *
24
24
 * Copyright:
25
 
 * 
 
25
 *
26
26
 *    Jochen Baier, 2004, 2005, 2006 (email@Jochen-Baier.de)
27
27
 *
28
28
 *
36
36
 *    dsimple.c ("The Open Group")
37
37
 *    xfwm4 (Olivier Fourdan <fourdan@xfce.org>)
38
38
 *    .....lot more, THANX !!!
39
 
 *    
 
39
 *
40
40
*/
41
41
 
42
42
 
51
51
{
52
52
 
53
53
  win->parent_is_visible=new_state;
54
 
    
 
54
 
55
55
}
56
56
 
57
57
static GdkFilterReturn
58
 
root_filter_manager_window (GdkXEvent *xevent, 
 
58
root_filter_manager_window (GdkXEvent *xevent,
59
59
  GdkEvent *event, gpointer user_data)
60
60
{
61
 
  
 
61
 
62
62
  XEvent *xev = (XEvent *)xevent;
63
 
  
 
63
 
64
64
  //win_struct *win= (win_struct *) user_data;
65
 
  
 
65
 
66
66
  if (debug) printf ("root_filter_manager_window event\n");
67
 
  
 
67
 
68
68
  if (xev->xany.type == ClientMessage &&
69
69
    xev->xclient.message_type == manager_atom &&
70
70
    xev->xclient.data.l[1] == selection_atom) {
71
 
  
 
71
 
72
72
    display_window_id (GDK_DISPLAY(), xev->xclient.window);
73
 
  
 
73
 
74
74
    if (debug) printf ("manager: here i am\n");
75
 
  
 
75
 
76
76
    gtk_main_quit ();
77
77
 
78
78
  }
79
 
  
 
79
 
80
80
  return GDK_FILTER_CONTINUE;
81
81
}
82
82
 
86
86
  win->manager_window=get_manager_window();
87
87
 
88
88
  if (win->manager_window == None) {
89
 
   
 
89
 
90
90
     printf ("\nAlltray: no system tray/notification area found.\n"\
91
91
             "I will wait..... I have time....\n\n"\
92
92
             "In the meantime you may add a system tray applet\n"\
93
93
             "to the panel.\n");
94
 
               
 
94
 
95
95
     gdk_window_add_filter(win->root_gdk, root_filter_manager_window, (gpointer) win);
96
96
     gtk_main ();
97
97
     gdk_window_remove_filter(win->root_gdk, root_filter_manager_window, (gpointer) win);
98
98
   }
99
 
 
 
99
 
100
100
  else { if (debug) printf ("HAVE MANAGER WINDOW\n");};
101
101
}
102
102
 
103
 
GdkFilterReturn parent_window_filter (GdkXEvent *xevent, 
 
103
GdkFilterReturn parent_window_filter (GdkXEvent *xevent,
104
104
  GdkEvent *event, gpointer user_data)
105
105
{
106
106
  XEvent *xev = (XEvent *)xevent;
107
107
  XConfigureEvent *xconfigure;
108
108
  XVisibilityEvent *xvisibilty;
109
109
  XConfigureRequestEvent *xconfigurerequest;
110
 
  
 
110
 
111
111
  gint return_type=GDK_FILTER_CONTINUE;
112
 
    
 
112
 
113
113
  win_struct *win= (win_struct*) user_data;
114
114
 
115
115
  switch (xev->xany.type) {
116
 
    
117
 
    
 
116
 
 
117
 
118
118
    case MapNotify:
119
 
      
 
119
 
120
120
     if (debug) printf ("map notify\n");
121
 
    
 
121
 
122
122
     update_visibility_state (win, window_is_visible);
123
 
    
 
123
 
124
124
    break;
125
 
    
 
125
 
126
126
    case UnmapNotify:
127
 
      
 
127
 
128
128
     if (debug) printf ("unmap notify\n");
129
 
    
 
129
 
130
130
     update_visibility_state (win, window_is_hidden);
131
 
       
132
 
    
 
131
 
 
132
 
133
133
    break;
134
 
     
 
134
 
135
135
    case ConfigureNotify:
136
 
    
137
 
      //if (debug) printf ("configure notify\n");  
138
 
      
 
136
 
 
137
      //if (debug) printf ("configure notify\n");
 
138
 
139
139
      xconfigure = (XConfigureEvent*) xev;
140
 
      
 
140
 
141
141
      static gint old_width=0;
142
142
      static gint old_height=0;
143
 
      
 
143
 
144
144
      if (old_width == xconfigure->width && old_height == xconfigure->height)
145
145
        break;
146
146
 
147
147
      old_width=xconfigure->width;
148
148
      old_height=xconfigure->height;
149
 
      
 
149
 
150
150
      gdk_window_resize (win->child_gdk, old_width, old_height);
151
151
 
152
152
    break;
153
 
      
 
153
 
154
154
    case ClientMessage:
155
155
 
156
156
      if (xev->xclient.data.l[0] == wm_delete_window) {
157
157
        if (debug) printf ("delete event!\n");
158
 
        
 
158
 
159
159
        show_hide_window (win, force_hide, FALSE);
160
160
        break;
161
161
      }
162
 
      
 
162
 
163
163
      if (xev->xclient.data.l[0] == wm_take_focus) {
164
164
        if (debug) printf ("wm take focus !!!\n");
165
 
          
 
165
 
166
166
        if (!assert_window(win->child_xlib)) {
167
167
          if (debug) printf ("can not set focus to child ! assert(window) failed\n");
168
168
          break;
169
169
        }
170
 
        
 
170
 
171
171
        while (!xlib_window_is_viewable (win->child_xlib))
172
172
          gtk_sleep (10);
173
 
                
174
 
        XSetInputFocus (win->display, win->child_xlib, 
 
173
 
 
174
        XSetInputFocus (win->display, win->child_xlib,
175
175
          RevertToParent, xev->xclient.data.l[1]);
176
 
        
 
176
 
177
177
        break;
178
 
      }   
179
 
      
 
178
      }
 
179
 
180
180
      if (xev->xclient.data.l[0] == net_wm_ping) {
181
181
        if (debug) printf ("net wm ping!\n");
182
 
        
 
182
 
183
183
        XEvent xe = *xev;
184
 
        
 
184
 
185
185
        xe.xclient.window = win->root_xlib;
186
 
        XSendEvent (win->display, win->root_xlib, False, 
 
186
        XSendEvent (win->display, win->root_xlib, False,
187
187
          SubstructureRedirectMask | SubstructureNotifyMask, &xe);
188
 
        
 
188
 
189
189
        break;
190
 
      }   
191
 
     
 
190
      }
 
191
 
192
192
      break;
193
 
     
 
193
 
194
194
      case VisibilityNotify:
195
 
        
 
195
 
196
196
        xvisibilty = (XVisibilityEvent*) xev;
197
 
      
 
197
 
198
198
        win->visibility=xvisibilty->state;
199
 
              
 
199
 
200
200
        if (debug) printf ("visibility notify state: %d\n", win->visibility);
201
201
      break;
202
202
 
203
 
        
 
203
 
204
204
      /*bad child wanted to move inside parent -> deny*/
205
205
      case ConfigureRequest:
206
 
        
 
206
 
207
207
      xconfigurerequest = (XConfigureRequestEvent*) xev;
208
 
              
 
208
 
209
209
      if (debug) printf ("child configure request\n");
210
210
 
211
211
      if (xconfigurerequest->x !=0  || xconfigurerequest->y != 0) {
212
 
        
 
212
 
213
213
        if (debug) printf ("deny configure request\n");
214
214
        return_type=GDK_FILTER_REMOVE;
215
215
      }
216
 
      
 
216
 
217
217
      break;
218
 
      
219
 
      
 
218
 
 
219
 
220
220
  }
221
 
  
 
221
 
222
222
   return return_type;
223
223
}
224
224
 
225
225
gboolean parse_arguments(int argc, char **argv, gchar **icon,
226
226
    gchar  **rest, gboolean *show, gboolean *debug, gboolean *borderless, gboolean *sticky,
227
 
    gboolean *skip_tasklist, gboolean *no_title, gboolean *configure, gboolean *large_icons, 
 
227
    gboolean *skip_tasklist, gboolean *configure, gboolean *large_icons,
228
228
    GArray *command_menu, gint *title_time, gchar **geometry,
229
229
    unsigned int *shortcut_key, unsigned int *shortcut_modifier, gboolean *notray, gboolean *nomini)
230
230
{
235
235
 
236
236
 
237
237
  int x, y, w, h;
238
 
  
 
238
 
239
239
  if (argc == 1) {
240
240
    show_help();
241
241
    return FALSE;
242
 
  }  
243
 
  
 
242
  }
 
243
 
244
244
  for (i = 1; i < argc; i++) {
245
 
  
 
245
 
246
246
    do {
247
 
    
 
247
 
248
248
      if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
249
249
        show_help();
250
250
        return FALSE;
251
251
      }
252
 
      
 
252
 
253
253
      if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-v")) {
254
254
        show_version();
255
255
        return FALSE;
256
256
      }
257
 
        
 
257
 
258
258
      if (!strcmp(argv[i], "--show") || !strcmp(argv[i], "-s")) {
259
259
        *show=TRUE;
260
260
        break;
261
 
      }  
262
 
     
 
261
      }
 
262
 
263
263
      if (!strcmp(argv[i], "--borderless") || !strcmp(argv[i], "-x")) {
264
264
        *borderless=TRUE;
265
265
        break;
268
268
      if (!strcmp(argv[i], "--notray") || !strcmp(argv[i], "-nt")) {
269
269
        *notray=TRUE;
270
270
        break;
271
 
      }    
 
271
      }
272
272
 
273
273
      if (!strcmp(argv[i], "--nominimize") || !strcmp(argv[i], "-nm")) {
274
274
        *nomini=TRUE;
275
275
        break;
276
 
      }    
 
276
      }
277
277
 
278
278
      if (!strcmp(argv[i], "--sticky") || !strcmp(argv[i], "-st")) {
279
279
        *sticky=TRUE;
280
280
        break;
281
281
      }
282
 
    
 
282
 
283
283
      if (!strcmp(argv[i], "--skip-taskbar") || !strcmp(argv[i], "-stask")) {
284
284
        *skip_tasklist=TRUE;
285
285
        break;
286
286
      }
287
 
    
288
 
      if (!strcmp(argv[i], "--no-alltray") || !strcmp(argv[i], "-na")) {
289
 
        *no_title=TRUE;
290
 
        break;
291
 
      }
292
287
 
293
288
      if (!strcmp(argv[i], "--configure") || !strcmp(argv[i], "-conf")) {
294
289
        *configure=TRUE;
295
290
        break;
296
 
      } 
297
 
      
 
291
      }
 
292
 
298
293
      if (!strcmp(argv[i], "--large_icons") || !strcmp(argv[i], "-l")) {
299
294
        *large_icons=TRUE;
300
295
        break;
301
 
      }  
302
 
    
303
 
         
 
296
      }
 
297
 
304
298
      if (!strcmp(argv[i], "--icon") || !strcmp(argv[i], "-i")) {
305
299
        if ((i+1) ==  argc) {
306
300
          show_help();
307
301
          return FALSE;
308
302
        }
309
 
      
 
303
 
310
304
        *icon=g_strdup (argv[i+1]);
311
305
        i++;
312
306
        break;
317
311
            show_help();
318
312
            return FALSE;
319
313
          }
320
 
        
 
314
 
321
315
          shortcut=g_strdup (argv[i+1]);
322
 
        
 
316
 
323
317
          if (!parse_shortcut (shortcut, shortcut_key, shortcut_modifier))
324
318
            return FALSE;
325
 
          
 
319
 
326
320
          g_free (shortcut);
327
 
                               
 
321
 
328
322
          i++;
329
323
          break;
330
 
     }            
331
 
      
 
324
     }
 
325
 
332
326
     if (!strcmp(argv[i], "--geometry") || !strcmp(argv[i], "-g")) {
333
327
        if ((i+1) ==  argc) {
334
328
          show_help();
335
329
          return FALSE;
336
330
        }
337
 
      
 
331
 
338
332
        *geometry=g_strdup (argv[i+1]);
339
 
        
 
333
 
340
334
        if (XParseGeometry(*geometry, &x, &y, (unsigned int *) &w, (unsigned int *) &h) == 0) {
341
335
          show_help();
342
336
          return FALSE;
343
337
        }
344
 
        
 
338
 
345
339
        i++;
346
340
        break;
347
 
     } 
348
 
      
 
341
     }
 
342
 
349
343
     if (!strcmp(argv[i], "--title") || !strcmp(argv[i], "-t")) {
350
344
      if ((i+1) ==  argc) {
351
345
        show_help();
352
346
        return FALSE;
353
347
      }
354
 
    
 
348
 
355
349
      *title_time=atoi (argv[i+1]);
356
 
      
 
350
 
357
351
      if (*title_time == 0) {
358
352
        show_help ();
359
353
        return FALSE;
360
354
      }
361
 
      
 
355
 
362
356
      i++;
363
357
      break;
364
358
    }
365
 
      
 
359
 
366
360
    if (!strcmp(argv[i], "--menu") || !strcmp(argv[i], "-m")) {
367
361
      if ((i+1) ==  argc) {
368
362
        show_help();
369
363
        return FALSE;
370
364
      }
371
 
      
 
365
 
372
366
      if (!append_command_to_menu(command_menu, argv[i+1])) {
373
367
        printf ("\nAllTray: \"%s\" is not a valid menu entry !\n"\
374
368
        "         Syntax: -m \"menu text:command\"\n", argv[i+1]);
375
369
        return FALSE;
376
370
      }
377
 
                      
 
371
 
378
372
      i++;
379
373
      break;
380
374
    }
382
376
    if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d")) {
383
377
      *debug=TRUE;
384
378
      break;
385
 
    }  
 
379
    }
386
380
 
387
381
  /*if (g_str_has_prefix (argv[i],"-")) {
388
382
      printf ("\nAlltray: Unknown option '%s'\n\n", argv[i]);
389
383
      return FALSE;
390
384
    }*/
391
 
    
 
385
 
392
386
    if (rest_buf == NULL) {
393
387
      rest_buf=g_strdup (argv[i]);
394
388
    } else {
396
390
      rest_buf=g_strconcat (rest_buf, " ", argv[i], NULL);
397
391
      g_free (tmp);
398
392
    }
399
 
        
 
393
 
400
394
    } until;
401
 
    
 
395
 
402
396
  }
403
 
  
404
 
  if (rest_buf && strlen (rest_buf) == 0 && !*configure) {
 
397
 
 
398
  if (!rest_buf || (rest_buf && strlen (rest_buf) == 0 && !*configure)) {
405
399
    show_help();
406
400
    return FALSE;
407
401
  }
413
407
 
414
408
gboolean append_command_to_menu(GArray *command_menu, gchar *string)
415
409
{
416
 
  
 
410
 
417
411
  command_menu_struct new;
418
 
  
 
412
 
419
413
  new.entry=NULL;
420
414
  new.command=NULL;
421
 
    
 
415
 
422
416
  gchar *tmp=NULL;
423
417
  gchar *command=NULL;
424
 
  
 
418
 
425
419
  tmp=g_strdup (string);
426
 
  
 
420
 
427
421
  if (!tmp)
428
422
    return FALSE;
429
 
        
 
423
 
430
424
  command = g_strrstr (tmp,":");
431
 
  
 
425
 
432
426
  if (debug) printf ("command: %s\n", command);
433
 
    
 
427
 
434
428
  if (!command) {
435
429
    g_free (tmp);
436
430
    return FALSE;
437
431
  }
438
 
  
 
432
 
439
433
  new.command=g_strdup(++command);
440
 
  
 
434
 
441
435
  if (strlen (new.command) == 0) {
442
436
    g_free (tmp);
443
437
    g_free (new.command);
444
438
    return FALSE;
445
439
  }
446
 
   
 
440
 
447
441
  if (debug) printf ("new.command: %s\n", new.command);
448
 
  
 
442
 
449
443
  *(--command)=0;
450
 
  
 
444
 
451
445
  if (strlen (tmp) == 0) {
452
446
    g_free (tmp);
453
447
    g_free (new.command);
454
448
    return FALSE;
455
449
  }
456
 
  
 
450
 
457
451
  new.entry=tmp;
458
 
    
 
452
 
459
453
  if (debug) printf ("new.entry: %s\n", new.entry);
460
 
    
 
454
 
461
455
  g_array_append_val(command_menu, new);
462
 
  
 
456
 
463
457
  return TRUE;
464
458
}
465
459
 
472
466
 
473
467
  command_copy=g_strdup (win->command);
474
468
 
475
 
  space=g_strstr_len (command_copy, 
 
469
  space=g_strstr_len (command_copy,
476
470
      strlen (command_copy) , " ");
477
 
  
 
471
 
478
472
  if (space)
479
473
    *space=0;
480
 
  
 
474
 
481
475
  if (debug) printf ("command without args: %s\n", command_copy);
482
476
 
483
477
  basename=g_path_get_basename (command_copy);
484
 
  
 
478
 
485
479
  if (debug) printf ("basename: %s\n", basename);
486
 
  
 
480
 
487
481
  g_free (command_copy);
488
 
  
 
482
 
489
483
  return basename;
490
484
 
491
485
}
493
487
void show_help(void)
494
488
{
495
489
  printf ("\nAllTray Version %s\n\n" \
496
 
  
 
490
 
497
491
             "Dock any program into the system tray.\n\n"  \
498
492
 
499
493
             "usage: alltray [options] [\"] <program_name> [program parameter] [\"]\n\n" \
506
500
             "   --large_icons; -l: allow large icons (> 24x24)\n"\
507
501
             "   --sticky; -st: visible on all workspaces\n"\
508
502
             "   --skip-taskbar; -stask: not visible in taskbar\n"\
509
 
             "   --no-alltray; -na: no \"(Alltray)\" in window title\n"\
510
503
             "   --borderless; -x: remove border, title, frame (if not supported native)\n"\
511
504
             "   --menu; -m: \"menu text:command\": add entry to popdown menu\n" \
512
505
             "   --title; -t <sec>: show tooltip with title for <sec> seconds after song change\n"\
515
508
             "     Modifier=\"Shift\", \"Control\", \"Alt\", \"AltGr\"\n"\
516
509
             "     Key (Examples) = \"a\", \"F1\", \"End\" ...\n"\
517
510
             "     or \"Keycode\" (Number) returned by the program \"xev\"\n"\
518
 
             "   --notray; -nt: display no tray icon (usefull only with the \"--key\" option)\n"\
 
511
             "   --notray; -nt: display no tray icon (useful only with the \"--key\" option)\n"\
519
512
             "   --nominimize; -nm: click on window close button: do not minimize back to system tray, close\n"\
520
513
            "   --configure; -conf: show KDE configuration dialog\n\n"\
521
514
             "usage: alltray\n\n"\