~ubuntu-branches/ubuntu/karmic/alltray/karmic

« back to all changes in this revision

Viewing changes to src/clickmode.c

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Hertzog
  • Date: 2007-01-14 18:36:56 UTC
  • Revision ID: james.westby@ubuntu.com-20070114183656-tutd3t7x0kifep7a
Tags: upstream-0.69
ImportĀ upstreamĀ versionĀ 0.69

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * GPL Notice:
 
3
 *
 
4
 *    This program is free software; you can redistribute it and/or modify
 
5
 *    it under the terms of the GNU General Public License as published by
 
6
 *    the Free Software Foundation; either version 2 of the License, or
 
7
 *    (at your option) any later version.
 
8
 *
 
9
 *    This program is distributed in the hope that it will be useful,
 
10
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *    GNU Library General Public License for more details.
 
13
 *
 
14
 *    You should have received a copy of the GNU General Public License
 
15
 *    along with this program; if not, write to the Free Software
 
16
 *    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 *
 
18
 *
 
19
 * Name:
 
20
 *
 
21
 *    alltray
 
22
 *
 
23
 *
 
24
 * Copyright:
 
25
 * 
 
26
 *    Jochen Baier, 2004, 2005, 2006 (email@Jochen-Baier.de)
 
27
 *
 
28
 *
 
29
 * Based on code from:
 
30
 *
 
31
 *    steal-xwin.c (acano@systec.com)
 
32
 *    xswallow (Caolan McNamara ?)
 
33
 *    kdocker (Girish Ramakrishnan)
 
34
 *    libwnck (Havoc Pennington <hp@redhat.com>)
 
35
 *    eggtrayicon (Anders Carlsson <andersca@gnu.org>)
 
36
 *    dsimple.c ("The Open Group")
 
37
 *    xfwm4 (Olivier Fourdan <fourdan@xfce.org>)
 
38
 *    .....lot more, THANX !!!
 
39
 *    
 
40
*/
 
41
 
 
42
#include "config.h"
 
43
#include "common.h"
 
44
#include "utils.h"
 
45
#include "clientwin.h"
 
46
 
 
47
GtkWidget *dialog;  
 
48
Window dialog_xlib;
 
49
GtkWidget *label3;    
 
50
 
 
51
static gint
 
52
expose_handler (GtkWidget       *widget,
 
53
                                        GdkEventExpose  *event,
 
54
                                        gpointer         user_data)
 
55
{
 
56
  gtk_paint_flat_box (widget->style, widget->window,
 
57
                      GTK_STATE_NORMAL, GTK_SHADOW_OUT, 
 
58
                      NULL, widget, "tooltip",
 
59
                      0, 0, -1, -1);
 
60
 
 
61
  gdk_draw_rectangle (widget->window, widget->style->black_gc, 
 
62
    0,  label3->allocation.x+4,  label3->allocation.y+2,  
 
63
    label3->allocation.width-8, label3->allocation.height-3);
 
64
 
 
65
  return FALSE;
 
66
}
 
67
 
 
68
GtkWidget*
 
69
create_dialog (void)
 
70
{
 
71
  GtkWidget *window1;
 
72
  GtkWidget *vbox1;
 
73
  GtkWidget *label1;
 
74
  GtkWidget *hseparator1;
 
75
  GtkWidget *label2;
 
76
 
 
77
 
 
78
  window1 = gtk_window_new (GTK_WINDOW_POPUP);
 
79
  gtk_container_set_border_width (GTK_CONTAINER (window1), 8);
 
80
  gtk_window_set_title (GTK_WINDOW (window1), "alltray-clickmode");
 
81
  gtk_window_set_position (GTK_WINDOW (window1), GTK_WIN_POS_CENTER);
 
82
  gtk_window_set_resizable (GTK_WINDOW (window1), FALSE);
 
83
  gtk_window_set_decorated (GTK_WINDOW (window1), FALSE);
 
84
  gtk_widget_set_app_paintable (window1, TRUE); 
 
85
  gtk_window_set_policy (GTK_WINDOW (window1), FALSE, FALSE, TRUE); 
 
86
 
 
87
  vbox1 = gtk_vbox_new (FALSE, 0);
 
88
  gtk_widget_show (vbox1);
 
89
  gtk_container_add (GTK_CONTAINER (window1), vbox1);
 
90
 
 
91
  label1 = gtk_label_new ("AllTray");
 
92
  gtk_widget_show (label1);
 
93
  gtk_box_pack_start (GTK_BOX (vbox1), label1, FALSE, FALSE, 0);
 
94
  gtk_misc_set_padding (GTK_MISC (label1), 0, 1);
 
95
 
 
96
  hseparator1 = gtk_hseparator_new ();
 
97
  gtk_widget_show (hseparator1);
 
98
  gtk_box_pack_start (GTK_BOX (vbox1), hseparator1, TRUE, TRUE, 0);
 
99
 
 
100
  label2 = gtk_label_new ("Please click on the window\nyou would like to dock.");
 
101
  gtk_widget_show (label2);
 
102
  gtk_box_pack_start (GTK_BOX (vbox1), label2, FALSE, FALSE, 0);
 
103
  gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_CENTER);
 
104
  gtk_misc_set_padding (GTK_MISC (label2), 0, 2);
 
105
 
 
106
  label3 = gtk_label_new ("Cancel");
 
107
  gtk_widget_show (label3);
 
108
  gtk_box_pack_start (GTK_BOX (vbox1), label3, FALSE, FALSE, 0);
 
109
  gtk_misc_set_padding (GTK_MISC (label3), 0, 6);
 
110
 
 
111
 
 
112
  g_signal_connect ((gpointer) window1, "expose_event",
 
113
                    G_CALLBACK (expose_handler),
 
114
                    NULL);      
 
115
  
 
116
 
 
117
  return window1;
 
118
}                                
 
119
 
 
120
 
 
121
static GdkFilterReturn root_filter (GdkXEvent *xevent, 
 
122
    GdkEvent *event2, gpointer user_data)
 
123
{
 
124
  XEvent *event = (XEvent *)xevent;
 
125
  Window target_win = None;
 
126
  Window target_win_xmu = None; 
 
127
 
 
128
  win_struct *win= (win_struct*) user_data; 
 
129
 
 
130
  switch (event->type) {
 
131
   
 
132
    case ButtonPress:  
 
133
 
 
134
      target_win= event->xbutton.subwindow;
 
135
      target_win_xmu=ClientWindow (target_win);
 
136
      
 
137
      //if (debug) printf ("target win: %d\n", target_win);
 
138
      //if (debug) printf ("target win xmu : %d\n", target_win_xmu);
 
139
        
 
140
        if (target_win == dialog_xlib || (
 
141
 
 
142
             target_win != None &&
 
143
             target_win != GDK_ROOT_WINDOW() &&
 
144
             target_win != target_win_xmu &&
 
145
             window_type_is_normal (target_win_xmu))) {
 
146
 
 
147
              gdk_pointer_ungrab  (GDK_CURRENT_TIME); 
 
148
              gdk_window_remove_filter (gdk_get_default_root_window (), root_filter, NULL);
 
149
              gtk_widget_destroy(dialog); 
 
150
 
 
151
            if (target_win == dialog_xlib) {
 
152
              if (debug) printf ("cancle");
 
153
              
 
154
              exit (0);
 
155
            } else  {
 
156
              if (debug) printf ("found alltrayable window");
 
157
              win->child_xlib=target_win_xmu;
 
158
              gtk_main_quit (); 
 
159
            }
 
160
  
 
161
          }
 
162
 
 
163
    break;
 
164
 
 
165
  }
 
166
 
 
167
  return GDK_FILTER_CONTINUE;
 
168
 
 
169
}
 
170
 
 
171
void new_grab (win_struct *win)
 
172
{
 
173
 
 
174
  GdkCursor *cursor = gdk_cursor_new (GDK_CROSSHAIR);
 
175
    gdk_pointer_grab (gdk_get_default_root_window() , FALSE, GDK_BUTTON_PRESS_MASK, 
 
176
      gdk_get_default_root_window(), cursor, GDK_CURRENT_TIME);
 
177
       
 
178
  gdk_cursor_unref (cursor);
 
179
  gdk_window_add_filter (gdk_get_default_root_window(), root_filter, win);            
 
180
 
 
181
}
 
182
 
 
183
void click_mode(win_struct *win)
 
184
{
 
185
 
 
186
  dialog=create_dialog();
 
187
  gtk_widget_show (dialog);
 
188
 
 
189
  dialog_xlib=GDK_WINDOW_XID(dialog->window);
 
190
 
 
191
  new_grab(win);
 
192
 
 
193
  gtk_main ();
 
194
 
 
195
}