summaryrefslogtreecommitdiff
path: root/recipes/scim/files/53_scim-1.4.7-trayicon.dpatch
blob: 666d39ef86cd83da1f0c3ce3279beb2819043013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#! /bin/sh /usr/share/dpatch/dpatch-run
## 53_scim-1.4.7-trayicon.dpatch by Ikuya Awashiro <ikuya@fruitsbasket.info>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Use better tray icon
## DP: https://bugzilla.redhat.com/show_bug.cgi?id=447848

@DPATCH@
diff -urNad scim-1.4.9~/extras/panel/scim_panel_gtk.cpp scim-1.4.9/extras/panel/scim_panel_gtk.cpp
--- scim-1.4.9~/extras/panel/scim_panel_gtk.cpp	2008-11-02 06:43:13.000000000 +0000
+++ scim-1.4.9/extras/panel/scim_panel_gtk.cpp	2009-07-20 11:54:40.000000000 +0000
@@ -60,7 +60,7 @@
 #include "scimstringview.h"
 
 #if ENABLE_TRAY_ICON
-  #include "scimtrayicon.h"
+//  #include "scimtrayicon.h"
 #endif
 
 using namespace scim;
@@ -276,6 +276,13 @@
 #if ENABLE_TRAY_ICON
 static void       ui_tray_icon_destroy_cb              (GtkObject      *object,
                                                         gpointer        user_data);
+static void       ui_tray_icon_popup_menu_cb           (GtkStatusIcon  *status_icon,
+                                                        guint           button, 
+                                                        guint           activate_time,
+                                                        gpointer        user_data);
+
+static void       ui_tray_icon_activate_cb             (GtkStatusIcon  *status_icon,
+                                                        gpointer        user_data);
 #endif
 
 // Client Property Callback
@@ -399,9 +406,9 @@
 static PangoFontDescription *_default_font_desc        = 0;
 
 #if ENABLE_TRAY_ICON
-static ScimTrayIcon      *_tray_icon                   = 0;
-static GtkWidget         *_tray_icon_factory_button    = 0;
-static gulong             _tray_icon_destroy_signal_id = 0;
+static GtkStatusIcon     *_tray_icon                   = 0;
+// static GtkWidget         *_tray_icon_factory_button    = 0;
+// static gulong             _tray_icon_destroy_signal_id = 0;
 #endif
 
 static gboolean           _input_window_draging        = FALSE;
@@ -647,9 +654,9 @@
 
 #if ENABLE_TRAY_ICON
     if (_tray_icon) {
-        g_signal_handler_disconnect (G_OBJECT (_tray_icon),
-                                     _tray_icon_destroy_signal_id);
-        gtk_widget_destroy (GTK_WIDGET (_tray_icon));
+        // g_signal_handler_disconnect (G_OBJECT (_tray_icon),
+        //                             _tray_icon_destroy_signal_id);
+        g_object_unref (_tray_icon);
     }
     _tray_icon = 0;
 #endif
@@ -1312,9 +1319,9 @@
         }
 
 #if ENABLE_TRAY_ICON
-        if (_tray_icon) {
-            gtk_window_set_screen (GTK_WINDOW (_tray_icon), screen);
-        }
+        // if (_tray_icon) {
+        //     gtk_window_set_screen (GTK_WINDOW (_tray_icon), screen);
+        // }
 #endif
 
         if (_help_dialog) {
@@ -1337,65 +1344,75 @@
 #endif
 
 #if ENABLE_TRAY_ICON
-static gboolean
-ui_tray_icon_expose_event_cb (GtkWidget *widget, GdkEventExpose *event)
-{
-    gdk_window_clear_area (widget->window, event->area.x, event->area.y,
-                           event->area.width, event->area.height);
-    return FALSE;
-}
-
-static void
-ui_tray_icon_style_set_cb (GtkWidget *widget, GtkStyle *previous_style)
-{
-    gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
-}
-
-static void
-ui_tray_icon_realize_cb (GtkWidget *widget)
-{
-    if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget))
-        return;
-
-    gtk_widget_set_app_paintable (widget, TRUE);
-    gtk_widget_set_double_buffered (widget, FALSE);
-    gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
-    g_signal_connect (widget, "expose_event",
-                      G_CALLBACK (ui_tray_icon_expose_event_cb), NULL);
-    g_signal_connect_after (widget, "style_set",
-                            G_CALLBACK (ui_tray_icon_style_set_cb), NULL);
-}
+// static gboolean
+// ui_tray_icon_expose_event_cb (GtkWidget *widget, GdkEventExpose *event)
+// {
+//     gdk_window_clear_area (widget->window, event->area.x, event->area.y,
+//                            event->area.width, event->area.height);
+//     return FALSE;
+// }
+// 
+// static void
+// ui_tray_icon_style_set_cb (GtkWidget *widget, GtkStyle *previous_style)
+// {
+//     gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
+// }
+// 
+// static void
+// ui_tray_icon_realize_cb (GtkWidget *widget)
+// {
+//     if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget))
+//         return;
+// 
+//     gtk_widget_set_app_paintable (widget, TRUE);
+//     gtk_widget_set_double_buffered (widget, FALSE);
+//     gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
+//     g_signal_connect (widget, "expose_event",
+//                       G_CALLBACK (ui_tray_icon_expose_event_cb), NULL);
+//     g_signal_connect_after (widget, "style_set",
+//                             G_CALLBACK (ui_tray_icon_style_set_cb), NULL);
+// }
 
 static gboolean
 ui_create_tray_icon_when_idle (gpointer data)
 {
     GtkWidget *image;
 
-    _tray_icon = scim_tray_icon_new ("SCIM Tray Icon");
-    g_signal_connect (G_OBJECT (_tray_icon), "realize",
-                      G_CALLBACK (ui_tray_icon_realize_cb), NULL);
+    _tray_icon = gtk_status_icon_new_from_file (SCIM_KEYBOARD_ICON_FILE);
+    // g_signal_connect (G_OBJECT (_tray_icon), "realize",
+    //                   G_CALLBACK (ui_tray_icon_realize_cb), NULL);
 
-    _tray_icon_destroy_signal_id = 
-    g_signal_connect (G_OBJECT (_tray_icon), "destroy",
-                      G_CALLBACK (ui_tray_icon_destroy_cb),
-                      0);
+    // _tray_icon_destroy_signal_id = 
+    // g_signal_connect (G_OBJECT (_tray_icon), "destroy",
+    //                   G_CALLBACK (ui_tray_icon_destroy_cb),
+    //                   0);
 
-    image = ui_create_icon (SCIM_KEYBOARD_ICON_FILE,
-                            NULL,
-                            TRAY_ICON_SIZE,
-                            TRAY_ICON_SIZE,
-                            true);
+    // image = ui_create_icon (SCIM_KEYBOARD_ICON_FILE,
+    //                         NULL,
+    //                         TRAY_ICON_SIZE,
+    //                         TRAY_ICON_SIZE,
+    //                         true);
 
-    _tray_icon_factory_button = gtk_event_box_new ();
-    g_signal_connect (G_OBJECT (_tray_icon_factory_button), "realize",
-                      G_CALLBACK (ui_tray_icon_realize_cb), NULL);
-    gtk_container_add (GTK_CONTAINER (_tray_icon_factory_button), image);
-    gtk_container_add (GTK_CONTAINER (_tray_icon), _tray_icon_factory_button);
-    g_signal_connect (G_OBJECT (_tray_icon_factory_button), "button-release-event",
-                      G_CALLBACK (ui_factory_button_click_cb),
+    // _tray_icon_factory_button = gtk_event_box_new ();
+    // g_signal_connect (G_OBJECT (_tray_icon_factory_button), "realize",
+    //                   G_CALLBACK (ui_tray_icon_realize_cb), NULL);
+    // gtk_container_add (GTK_CONTAINER (_tray_icon_factory_button), image);
+    // gtk_container_add (GTK_CONTAINER (_tray_icon), _tray_icon_factory_button);
+
+    
+    // g_signal_connect (G_OBJECT (_tray_icon_factory_button), "button-release-event",
+    //                   G_CALLBACK (ui_factory_button_click_cb),
+    //                   0);
+    
+    g_signal_connect (G_OBJECT (_tray_icon), "popup-menu",
+                      G_CALLBACK (ui_tray_icon_popup_menu_cb),
+                      0);
+    
+    g_signal_connect (G_OBJECT (_tray_icon), "activate",
+                      G_CALLBACK (ui_tray_icon_activate_cb),
                       0);
 
-    gtk_widget_show_all (GTK_WIDGET (_tray_icon));
+    gtk_status_icon_set_visible (_tray_icon, TRUE);
 
     return FALSE;
 }
@@ -1686,6 +1703,19 @@
 }
 
 static void
+ui_tray_icon_popup_menu_cb (GtkStatusIcon *status_icon, guint button, 
+    guint activate_time, gpointer user_data)
+{
+    action_show_command_menu ();
+}
+
+static void
+ui_tray_icon_activate_cb (GtkStatusIcon *status_icon, gpointer user_data)
+{
+    _panel_agent->request_factory_menu ();
+}
+
+static void
 ui_factory_menu_activate_cb (GtkMenuItem *item,
                              gpointer     user_data)
 {
@@ -2243,19 +2273,19 @@
 }
 
 #if ENABLE_TRAY_ICON
-static void
-ui_tray_icon_destroy_cb (GtkObject      *object,
-                         gpointer        user_data)
-{
-    SCIM_DEBUG_MAIN (1) << "Tray Icon destroyed!\n";
-
-    gtk_widget_destroy (GTK_WIDGET (object));
-
-    _tray_icon = 0;
-    _tray_icon_factory_button = 0;
-
-    g_idle_add (ui_create_tray_icon_when_idle, NULL);
-}
+// static void
+// ui_tray_icon_destroy_cb (GtkObject      *object,
+//                          gpointer        user_data)
+// {
+//     SCIM_DEBUG_MAIN (1) << "Tray Icon destroyed!\n";
+// 
+//     gtk_widget_destroy (GTK_WIDGET (object));
+// 
+//     _tray_icon = 0;
+//     _tray_icon_factory_button = 0;
+// 
+//     g_idle_add (ui_create_tray_icon_when_idle, NULL);
+// }
 #endif
 
 static void
@@ -2685,18 +2715,21 @@
     }
 
 #if ENABLE_TRAY_ICON
-    if (_tray_icon_factory_button) {
-        GtkWidget *icon = gtk_bin_get_child (GTK_BIN (_tray_icon_factory_button));
+    // if (_tray_icon_factory_button) {
+    //     GtkWidget *icon = gtk_bin_get_child (GTK_BIN (_tray_icon_factory_button));
 
-        if (icon)
-            gtk_container_remove (GTK_CONTAINER (_tray_icon_factory_button), icon);
+    //     if (icon)
+    //         gtk_container_remove (GTK_CONTAINER (_tray_icon_factory_button), icon);
 
-        icon = ui_create_icon (info.icon, NULL, TRAY_ICON_SIZE, TRAY_ICON_SIZE, true);
+    //     icon = ui_create_icon (info.icon, NULL, TRAY_ICON_SIZE, TRAY_ICON_SIZE, true);
 
-        gtk_container_add (GTK_CONTAINER (_tray_icon_factory_button), icon);
+    //     gtk_container_add (GTK_CONTAINER (_tray_icon_factory_button), icon);
 
-        if (_tooltips)
-            gtk_tooltips_set_tip (_tooltips, _tray_icon_factory_button, info.name.c_str (), NULL);
+    //     if (_tooltips)
+    //         gtk_tooltips_set_tip (_tooltips, _tray_icon_factory_button, info.name.c_str (), NULL);
+    // }
+    if (_tray_icon) {
+        gtk_status_icon_set_from_file (_tray_icon, info.icon.c_str());
     }
 #endif