1
/** @file scim_panel_gtk.cpp
5
* Smart Common Input Method
7
* Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2 of the License, or (at your option) any later version.
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this program; if not, write to the
22
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23
* Boston, MA 02111-1307 USA
25
* $Id: scim_panel_gtk.cpp,v 1.118.2.15 2007/04/11 11:30:31 suzhe Exp $
29
#include <sys/types.h>
36
#ifdef GDK_WINDOWING_X11
45
#define Uses_SCIM_LOOKUP_TABLE
46
#define Uses_SCIM_SOCKET
47
#define Uses_SCIM_TRANSACTION
48
#define Uses_SCIM_TRANS_COMMANDS
49
#define Uses_SCIM_CONFIG
50
#define Uses_SCIM_CONFIG_MODULE
51
#define Uses_SCIM_DEBUG
52
#define Uses_SCIM_HELPER
53
#define Uses_SCIM_HELPER_MODULE
54
#define Uses_SCIM_PANEL_AGENT
56
#include "scim_private.h"
58
#include "scim_stl_map.h"
60
#include "scimstringview.h"
63
// #include "scimtrayicon.h"
68
#include "icons/up.xpm"
69
#include "icons/down.xpm"
70
#include "icons/left.xpm"
71
#include "icons/right.xpm"
72
#include "icons/setup.xpm"
73
#include "icons/help.xpm"
74
#include "icons/trademark.xpm"
75
#include "icons/pin-up.xpm"
76
#include "icons/pin-down.xpm"
77
#include "icons/menu.xpm"
79
#define SCIM_CONFIG_PANEL_GTK_FONT "/Panel/Gtk/Font"
80
#define SCIM_CONFIG_PANEL_GTK_COLOR_NORMAL_BG "/Panel/Gtk/Color/NormalBackground"
81
#define SCIM_CONFIG_PANEL_GTK_COLOR_ACTIVE_BG "/Panel/Gtk/Color/ActiveBackground"
82
#define SCIM_CONFIG_PANEL_GTK_COLOR_NORMAL_TEXT "/Panel/Gtk/Color/NormalText"
83
#define SCIM_CONFIG_PANEL_GTK_COLOR_ACTIVE_TEXT "/Panel/Gtk/Color/ActiveText"
84
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_SHOW "/Panel/Gtk/ToolBar/AlwaysShow"
85
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_HIDDEN "/Panel/Gtk/ToolBar/AlwaysHidden"
86
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_AUTO_SNAP "/Panel/Gtk/ToolBar/AutoSnap"
87
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_HIDE_TIMEOUT "/Panel/Gtk/ToolBar/HideTimeout"
88
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_X "/Panel/Gtk/ToolBar/POS_X"
89
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_Y "/Panel/Gtk/ToolBar/POS_Y"
90
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_ICON "/Panel/Gtk/ToolBar/ShowFactoryIcon"
91
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_NAME "/Panel/Gtk/ToolBar/ShowFactoryName"
92
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_STICK_ICON "/Panel/Gtk/ToolBar/ShowStickIcon"
93
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_HELP_ICON "/Panel/Gtk/ToolBar/ShowHelpIcon"
94
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_MENU_ICON "/Panel/Gtk/ToolBar/ShowMenuIcon"
95
#define SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_PROPERTY_LABEL "/Panel/Gtk/ToolBar/ShowPropertyLabel"
96
#define SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_EMBEDDED "/Panel/Gtk/LookupTableEmbedded"
97
#define SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_VERTICAL "/Panel/Gtk/LookupTableVertical"
98
#define SCIM_CONFIG_PANEL_GTK_DEFAULT_STICKED "/Panel/Gtk/DefaultSticked"
99
#define SCIM_CONFIG_PANEL_GTK_SHOW_TRAY_ICON "/Panel/Gtk/ShowTrayIcon"
101
#define SCIM_KEYBOARD_ICON_FILE (SCIM_ICONDIR "/keyboard.png")
102
#define SCIM_TRADEMARK_ICON_FILE (SCIM_ICONDIR "/trademark.png")
103
#define SCIM_SETUP_ICON_FILE (SCIM_ICONDIR "/setup.png")
104
#define SCIM_HELP_ICON_FILE (SCIM_ICONDIR "/help.png")
105
#define SCIM_MENU_ICON_FILE (SCIM_ICONDIR "/menu.png")
106
#define SCIM_UP_ICON_FILE (SCIM_ICONDIR "/up.png")
107
#define SCIM_DOWN_ICON_FILE (SCIM_ICONDIR "/down.png")
108
#define SCIM_LEFT_ICON_FILE (SCIM_ICONDIR "/left.png")
109
#define SCIM_RIGHT_ICON_FILE (SCIM_ICONDIR "/right.png")
110
#define SCIM_PIN_UP_ICON_FILE (SCIM_ICONDIR "/pin-up.png")
111
#define SCIM_PIN_DOWN_ICON_FILE (SCIM_ICONDIR "/pin-down.png")
113
#define TOOLBAR_ICON_SIZE 16
114
#define TRAY_ICON_SIZE 11
115
#define LOOKUP_ICON_SIZE 12
117
/////////////////////////////////////////////////////////////////////////////
118
// Declaration of internal data types.
119
/////////////////////////////////////////////////////////////////////////////
120
struct PropertyInfo {
124
PropertyInfo () : widget (0) { }
127
typedef std::vector <PropertyInfo> PropertyRepository;
129
struct HelperPropertyInfo {
131
PropertyRepository repository;
133
HelperPropertyInfo () : holder (0) { }
136
#if SCIM_USE_STL_EXT_HASH_MAP
137
typedef __gnu_cxx::hash_map <int, HelperPropertyInfo, __gnu_cxx::hash <int> > HelperPropertyRepository;
138
typedef __gnu_cxx::hash_map <String, std::vector <size_t>, scim_hash_string> MapStringVectorSizeT;
139
#elif SCIM_USE_STL_HASH_MAP
140
typedef std::hash_map <int, HelperPropertyInfo, std::hash <int> > HelperPropertyRepository;
141
typedef std::hash_map <String, std::vector <size_t>, scim_hash_string> MapStringVectorSizeT;
143
typedef std::map <int, HelperPropertyInfo> HelperPropertyRepository;
144
typedef std::map <String, std::vector <size_t> > MapStringVectorSizeT;
147
/////////////////////////////////////////////////////////////////////////////
148
// Declaration of internal functions.
149
/////////////////////////////////////////////////////////////////////////////
150
static void ui_config_reload_callback (const ConfigPointer &config);
151
static void ui_load_config (void);
152
static void ui_initialize (void);
154
static void ui_settle_input_window (bool relative = false,
156
static void ui_settle_lookup_table_window (bool force = false);
157
static void ui_settle_toolbar_window (bool force = false);
159
static int ui_screen_width (void);
160
static int ui_screen_height (void);
161
static void ui_get_workarea (int &x,
167
static gboolean ui_create_tray_icon_when_idle (gpointer data);
170
#if GDK_MULTIHEAD_SAFE
171
static void ui_switch_screen (GdkScreen *screen);
174
static GdkPixbuf* ui_scale_pixbuf (GdkPixbuf *pixbuf,
178
static GtkWidget* ui_create_label (const String &name,
179
const String &iconfile,
181
bool show_icon_only = false,
182
bool force_icon = false);
184
static GtkWidget* ui_create_icon (const String &iconfile,
185
const char **xpm = NULL,
188
bool force_create = false);
190
static GtkWidget* ui_create_trademark_icon (void);
191
static GtkWidget* ui_create_stick_icon (bool sticked);
192
static GtkWidget* ui_create_help_icon (void);
193
static GtkWidget* ui_create_menu_icon (void);
194
static GtkWidget* ui_create_up_icon (void);
195
static GtkWidget* ui_create_down_icon (void);
196
static GtkWidget* ui_create_left_icon (void);
197
static GtkWidget* ui_create_right_icon (void);
199
static GtkWidget* ui_create_factory_menu_entry (const PanelFactoryInfo &info,
205
// callback functions
206
static void ui_preedit_area_move_cursor_cb (ScimStringView *view,
209
static void ui_help_button_click_cb (GtkButton *button,
211
static void ui_menu_button_click_cb (GtkButton *button,
213
static gboolean ui_factory_button_click_cb (GtkWidget *button,
216
static void ui_factory_menu_activate_cb (GtkMenuItem *item,
218
static void ui_factory_menu_deactivate_cb (GtkMenuItem *item,
221
static gboolean ui_lookup_table_vertical_click_cb (GtkWidget *item,
222
GdkEventButton *event,
225
static void ui_lookup_table_horizontal_click_cb (GtkWidget *item,
228
static void ui_lookup_table_up_button_click_cb (GtkButton *button,
230
static void ui_lookup_table_down_button_click_cb (GtkButton *button,
233
static void ui_window_stick_button_click_cb (GtkButton *button,
236
static gboolean ui_input_window_motion_cb (GtkWidget *window,
237
GdkEventMotion *event,
239
static gboolean ui_input_window_click_cb (GtkWidget *window,
240
GdkEventButton *event,
242
static gboolean ui_toolbar_window_crossing_cb (GtkWidget *window,
243
GdkEventCrossing *event,
245
static gboolean ui_toolbar_window_motion_cb (GtkWidget *window,
246
GdkEventMotion *event,
248
static gboolean ui_toolbar_window_click_cb (GtkWidget *window,
249
GdkEventButton *event,
251
static gboolean ui_lookup_table_window_motion_cb (GtkWidget *window,
252
GdkEventMotion *event,
254
static gboolean ui_lookup_table_window_click_cb (GtkWidget *window,
255
GdkEventButton *event,
258
static gboolean ui_hide_window_timeout_cb (gpointer data);
260
static void ui_command_menu_exit_activate_cb (GtkMenuItem *item,
263
static void ui_command_menu_reload_activate_cb (GtkMenuItem *item,
265
static void ui_command_menu_stick_activate_cb (GtkMenuItem *item,
267
static void ui_command_menu_hide_toolbar_toggled_cb (GtkMenuItem *item,
269
static void ui_command_menu_help_activate_cb (GtkMenuItem *item,
271
static void ui_command_menu_helper_activate_cb (GtkWidget *item,
273
static void ui_command_menu_deactivate_cb (GtkWidget *item,
277
static void ui_tray_icon_destroy_cb (GtkObject *object,
279
static void ui_tray_icon_popup_menu_cb (GtkStatusIcon *status_icon,
284
static void ui_tray_icon_activate_cb (GtkStatusIcon *status_icon,
288
// Client Property Callback
289
static void ui_property_activate_cb (GtkWidget *widget,
292
static void ui_property_menu_deactivate_cb (GtkWidget *item,
295
static bool ui_can_hide_input_window (void);
297
static bool ui_any_menu_activated (void);
299
static void ui_show_help (const String &help);
301
static PangoAttrList * create_pango_attrlist (const String &str,
302
const AttributeList &attrs);
305
static void action_request_help (void);
306
static void action_toggle_window_stick (void);
307
static void action_show_command_menu (void);
309
// PanelAgent related functions
310
static bool initialize_panel_agent (const String &config, const String &display, bool resident);
311
static bool run_panel_agent (void);
312
static gpointer panel_agent_thread_func (gpointer data);
313
static void start_auto_start_helpers (void);
315
static void slot_transaction_start (void);
316
static void slot_transaction_end (void);
317
static void slot_reload_config (void);
318
static void slot_turn_on (void);
319
static void slot_turn_off (void);
320
static void slot_update_screen (int screen);
321
static void slot_update_spot_location (int x, int y);
322
static void slot_update_factory_info (const PanelFactoryInfo &info);
323
static void slot_show_help (const String &help);
324
static void slot_show_factory_menu (const std::vector <PanelFactoryInfo> &menu);
326
static void slot_show_preedit_string (void);
327
static void slot_show_aux_string (void);
328
static void slot_show_lookup_table (void);
329
static void slot_hide_preedit_string (void);
330
static void slot_hide_aux_string (void);
331
static void slot_hide_lookup_table (void);
332
static void slot_update_preedit_string (const String &str, const AttributeList &attrs);
333
static void slot_update_preedit_caret (int caret);
334
static void slot_update_aux_string (const String &str, const AttributeList &attrs);
335
static void slot_update_lookup_table (const LookupTable &table);
336
static void slot_register_properties (const PropertyList &props);
337
static void slot_update_property (const Property &prop);
339
static void slot_register_helper_properties (int id, const PropertyList &props);
340
static void slot_update_helper_property (int id, const Property &prop);
341
static void slot_register_helper (int id, const HelperInfo &helper);
342
static void slot_remove_helper (int id);
343
static void slot_lock (void);
344
static void slot_unlock (void);
347
static void create_properties (GtkWidget *container,
348
PropertyRepository &repository,
349
const PropertyList &properties,
353
static GtkWidget* create_properties_node (PropertyRepository &repository,
354
PropertyList::const_iterator begin,
355
PropertyList::const_iterator end,
359
static void register_frontend_properties (const PropertyList &properties);
360
static void update_frontend_property (const Property &property);
361
static void register_helper_properties (int client,
362
const PropertyList &properties);
363
static void update_helper_property (int client,
364
const Property &property);
366
static void update_property (PropertyRepository &repository,
367
const Property &property);
369
static void restore_properties (void);
371
static gboolean check_exit_timeout_cb (gpointer data);
374
/////////////////////////////////////////////////////////////////////////////
375
// Declaration of internal variables.
376
/////////////////////////////////////////////////////////////////////////////
377
#if GDK_MULTIHEAD_SAFE
378
static GdkScreen *_current_screen = 0;
381
static GtkWidget *_input_window = 0;
382
static GtkWidget *_preedit_area = 0;
383
static GtkWidget *_aux_area = 0;
385
static GtkWidget *_lookup_table_window = 0;
386
static GtkWidget *_lookup_table_up_button = 0;
387
static GtkWidget *_lookup_table_down_button = 0;
388
static GtkWidget *_lookup_table_items [SCIM_LOOKUP_TABLE_MAX_PAGESIZE];
390
static GtkWidget *_toolbar_window = 0;
391
static GtkWidget *_window_stick_button = 0;
392
static GtkWidget *_factory_button = 0;
393
static GtkWidget *_factory_menu = 0;
394
static GtkWidget *_help_button = 0;
395
static GtkWidget *_menu_button = 0;
396
static GtkWidget *_client_properties_area = 0;
397
static GtkWidget *_frontend_properties_area = 0;
399
static GtkWidget *_help_dialog = 0;
400
static GtkWidget *_help_scroll = 0;
401
static GtkWidget *_help_area = 0;
402
static GtkWidget *_command_menu = 0;
404
static GtkTooltips *_tooltips = 0;
406
static PangoFontDescription *_default_font_desc = 0;
409
static GtkStatusIcon *_tray_icon = 0;
410
// static GtkWidget *_tray_icon_factory_button = 0;
411
// static gulong _tray_icon_destroy_signal_id = 0;
414
static gboolean _input_window_draging = FALSE;
415
static gint _input_window_drag_x = 0;
416
static gint _input_window_drag_y = 0;
418
static gint _input_window_x = 0;
419
static gint _input_window_y = 0;
421
static gboolean _toolbar_window_draging = FALSE;
422
static gint _toolbar_window_drag_x = 0;
423
static gint _toolbar_window_drag_y = 0;
425
static gboolean _lookup_table_window_draging = FALSE;
426
static gint _lookup_table_window_drag_x = 0;
427
static gint _lookup_table_window_drag_y = 0;
428
static gint _lookup_table_window_x = 0;
429
static gint _lookup_table_window_y = 0;
431
static bool _lookup_table_embedded = true;
432
static bool _lookup_table_vertical = false;
433
static bool _window_sticked = false;
436
static bool _show_tray_icon = true;
439
static bool _toolbar_always_show = false;
440
static bool _toolbar_always_hidden = false;
441
static bool _toolbar_auto_snap = true;
442
static bool _toolbar_show_factory_icon = true;
443
static bool _toolbar_show_factory_name = false;
444
static bool _toolbar_show_stick_icon = false;
445
static bool _toolbar_show_help_icon = false;
446
static bool _toolbar_show_menu_icon = false;
447
static bool _toolbar_show_property_label = false;
449
static bool _toolbar_should_hide = false;
450
static bool _toolbar_hidden = false;
451
static bool _factory_menu_activated = false;
452
static bool _command_menu_activated = false;
453
static bool _property_menu_activated = false;
455
static int _spot_location_x = -1;
456
static int _spot_location_y = -1;
458
static int _toolbar_window_x = -1;
459
static int _toolbar_window_y = -1;
460
static int _toolbar_hide_timeout_max = 0;
461
static int _toolbar_hide_timeout_count = 0;
462
static guint _toolbar_hide_timeout = 0;
464
static bool _ui_initialized = false;
466
static int _lookup_table_index [SCIM_LOOKUP_TABLE_MAX_PAGESIZE+1];
468
static GdkColor _normal_bg;
469
static GdkColor _normal_text;
470
static GdkColor _active_bg;
471
static GdkColor _active_text;
473
static ConfigModule *_config_module = 0;
474
static ConfigPointer _config;
476
static guint _check_exit_timeout = 0;
478
static bool _should_exit = false;
480
static bool _panel_is_on = false;
482
static GThread *_panel_agent_thread = 0;
484
static PanelAgent *_panel_agent = 0;
486
static std::vector<String> _factory_menu_uuids;
488
static std::list<String> _recent_factory_uuids;
490
static struct timeval _last_menu_deactivate_time = {0, 0};
493
static PropertyRepository _frontend_property_repository;
494
static HelperPropertyRepository _helper_property_repository;
495
static std::vector<HelperInfo> _helper_list;
497
G_LOCK_DEFINE_STATIC (_global_resource_lock);
498
G_LOCK_DEFINE_STATIC (_panel_agent_lock);
501
/////////////////////////////////////////////////////////////////////////////
502
// Implementation of internal functions.
503
/////////////////////////////////////////////////////////////////////////////
505
ui_config_reload_callback (const ConfigPointer &config)
509
restore_properties ();
513
ui_load_config (void)
517
// Read configurations.
518
gdk_color_parse ("gray92", &_normal_bg);
519
gdk_color_parse ("black", &_normal_text);
520
gdk_color_parse ("light blue", &_active_bg);
521
gdk_color_parse ("black", &_active_text);
523
if (_default_font_desc) {
524
pango_font_description_free (_default_font_desc);
525
_default_font_desc = 0;
528
if (!_config.null ()) {
529
str = _config->read (String (SCIM_CONFIG_PANEL_GTK_FONT),
532
if (str != String ("default"))
533
_default_font_desc = pango_font_description_from_string (str.c_str ());
535
str = _config->read (String (SCIM_CONFIG_PANEL_GTK_COLOR_NORMAL_BG),
537
gdk_color_parse (str.c_str (), &_normal_bg);
539
str = _config->read (String (SCIM_CONFIG_PANEL_GTK_COLOR_NORMAL_TEXT),
541
gdk_color_parse (str.c_str (), &_normal_text);
543
str = _config->read (String (SCIM_CONFIG_PANEL_GTK_COLOR_ACTIVE_BG),
544
String ("light blue"));
545
gdk_color_parse (str.c_str (), &_active_bg);
547
str = _config->read (String (SCIM_CONFIG_PANEL_GTK_COLOR_ACTIVE_TEXT),
549
gdk_color_parse (str.c_str (), &_active_text);
551
_toolbar_window_x = _config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_X),
554
_toolbar_window_y = _config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_Y),
558
_config->read (String (SCIM_CONFIG_PANEL_GTK_DEFAULT_STICKED),
561
_lookup_table_vertical =
562
_config->read (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_VERTICAL),
563
_lookup_table_vertical);
565
_lookup_table_embedded =
566
_config->read (String (SCIM_CONFIG_PANEL_GTK_LOOKUP_TABLE_EMBEDDED),
567
_lookup_table_embedded);
569
_toolbar_always_show =
570
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_SHOW),
571
_toolbar_always_show);
573
_toolbar_always_hidden =
574
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_ALWAYS_HIDDEN),
575
_toolbar_always_hidden);
578
if (_toolbar_always_show && _toolbar_always_hidden)
579
_toolbar_always_hidden = false;
582
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_AUTO_SNAP),
585
_toolbar_show_factory_icon =
586
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_ICON),
587
_toolbar_show_factory_icon);
589
_toolbar_show_factory_name =
590
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_FACTORY_NAME),
591
_toolbar_show_factory_name);
593
_toolbar_show_stick_icon =
594
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_STICK_ICON),
595
_toolbar_show_stick_icon);
597
_toolbar_show_help_icon =
598
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_HELP_ICON),
599
_toolbar_show_help_icon);
601
_toolbar_show_menu_icon =
602
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_MENU_ICON),
603
_toolbar_show_menu_icon);
605
_toolbar_show_property_label =
606
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_SHOW_PROPERTY_LABEL),
607
_toolbar_show_property_label);
609
_toolbar_hide_timeout_max =
610
_config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_HIDE_TIMEOUT),
611
_toolbar_hide_timeout_max);
615
_config->read (String (SCIM_CONFIG_PANEL_GTK_SHOW_TRAY_ICON),
621
#ifdef GDK_WINDOWING_X11
622
static GdkFilterReturn
623
ui_event_filter (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
625
g_return_val_if_fail (gdk_xevent, GDK_FILTER_CONTINUE);
627
XEvent *xev = (XEvent*)gdk_xevent;
629
if (xev->type == PropertyNotify) {
630
if (xev->xproperty.atom == gdk_x11_get_xatom_by_name ("_NET_WORKAREA") ||
631
xev->xproperty.atom == gdk_x11_get_xatom_by_name ("_NET_CURRENT_DESKTOP")) {
632
ui_settle_toolbar_window ();
636
return GDK_FILTER_CONTINUE;
643
SCIM_DEBUG_MAIN (1) << "Initialize UI...\n";
645
GtkWidget *input_window_vbox;
648
_toolbar_hidden = false;
650
if (_lookup_table_window) gtk_widget_destroy (_lookup_table_window);
651
if (_input_window) gtk_widget_destroy (_input_window);
652
if (_toolbar_window) gtk_widget_destroy (_toolbar_window);
653
if (_help_dialog) gtk_widget_destroy (_help_dialog);
654
if (_tooltips) gtk_object_destroy (GTK_OBJECT (_tooltips));
658
// g_signal_handler_disconnect (G_OBJECT (_tray_icon),
659
// _tray_icon_destroy_signal_id);
660
g_object_unref (_tray_icon);
665
_lookup_table_window = 0;
671
#if GDK_MULTIHEAD_SAFE
672
// Initialize the Display and Screen.
673
_current_screen = gdk_screen_get_default ();
676
// Create input window
682
_input_window = gtk_window_new (GTK_WINDOW_POPUP);
683
gtk_widget_modify_bg (_input_window, GTK_STATE_NORMAL, &_normal_bg);
684
gtk_window_set_policy (GTK_WINDOW (_input_window), TRUE, TRUE, FALSE);
685
gtk_window_set_resizable (GTK_WINDOW (_input_window), FALSE);
686
gtk_widget_add_events (_input_window,GDK_BUTTON_PRESS_MASK);
687
gtk_widget_add_events (_input_window,GDK_BUTTON_RELEASE_MASK);
688
gtk_widget_add_events (_input_window,GDK_POINTER_MOTION_MASK);
689
g_signal_connect (G_OBJECT (_input_window), "button-press-event",
690
G_CALLBACK (ui_input_window_click_cb),
691
GINT_TO_POINTER (0));
692
g_signal_connect (G_OBJECT (_input_window), "button-release-event",
693
G_CALLBACK (ui_input_window_click_cb),
694
GINT_TO_POINTER (1));
696
frame = gtk_frame_new (0);
697
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
698
gtk_container_add (GTK_CONTAINER (_input_window), frame);
700
hbox = gtk_hbox_new (FALSE, 0);
701
gtk_container_add (GTK_CONTAINER (frame), hbox);
703
vbox = gtk_vbox_new (FALSE, 0);
704
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
705
input_window_vbox = vbox;
707
//Create preedit area
708
_preedit_area = scim_string_view_new ();
709
if (_default_font_desc)
710
gtk_widget_modify_font (_preedit_area, _default_font_desc);
711
gtk_widget_modify_base (_preedit_area, GTK_STATE_NORMAL, &_normal_bg);
712
gtk_widget_modify_base (_preedit_area, GTK_STATE_ACTIVE, &_active_bg);
713
gtk_widget_modify_text (_preedit_area, GTK_STATE_NORMAL, &_normal_text);
714
gtk_widget_modify_text (_preedit_area, GTK_STATE_ACTIVE, &_active_text);
715
scim_string_view_set_width_chars (SCIM_STRING_VIEW (_preedit_area), 24);
716
scim_string_view_set_forward_event (SCIM_STRING_VIEW (_preedit_area), TRUE);
717
scim_string_view_set_auto_resize (SCIM_STRING_VIEW (_preedit_area), TRUE);
718
scim_string_view_set_has_frame (SCIM_STRING_VIEW (_preedit_area), FALSE);
719
g_signal_connect (G_OBJECT (_preedit_area), "move_cursor",
720
G_CALLBACK (ui_preedit_area_move_cursor_cb),
722
gtk_box_pack_start (GTK_BOX (vbox), _preedit_area, TRUE, TRUE, 0);
725
_aux_area = scim_string_view_new ();
726
if (_default_font_desc)
727
gtk_widget_modify_font (_aux_area, _default_font_desc);
728
gtk_widget_modify_base (_aux_area, GTK_STATE_NORMAL, &_normal_bg);
729
gtk_widget_modify_base (_aux_area, GTK_STATE_ACTIVE, &_active_bg);
730
gtk_widget_modify_text (_aux_area, GTK_STATE_NORMAL, &_normal_text);
731
gtk_widget_modify_text (_aux_area, GTK_STATE_ACTIVE, &_active_text);
732
scim_string_view_set_width_chars (SCIM_STRING_VIEW (_aux_area), 24);
733
scim_string_view_set_draw_cursor (SCIM_STRING_VIEW (_aux_area), FALSE);
734
scim_string_view_set_forward_event (SCIM_STRING_VIEW (_aux_area), TRUE);
735
scim_string_view_set_auto_resize (SCIM_STRING_VIEW (_aux_area), TRUE);
736
scim_string_view_set_has_frame (SCIM_STRING_VIEW (_aux_area), FALSE);
737
gtk_box_pack_start (GTK_BOX (vbox), _aux_area, TRUE, TRUE, 0);
739
gtk_window_move (GTK_WINDOW (_input_window), ui_screen_width (), ui_screen_height ());
741
gtk_widget_show_all (_input_window);
742
gtk_widget_hide (_input_window);
745
//Create lookup table window
750
GtkWidget *lookup_table_parent;
752
GtkWidget *separator;
754
if (_lookup_table_embedded) {
755
_lookup_table_window = gtk_vbox_new (FALSE, 0);
756
gtk_box_pack_start (GTK_BOX (input_window_vbox), _lookup_table_window, TRUE, TRUE, 0);
757
lookup_table_parent = _lookup_table_window;
758
separator = gtk_hseparator_new ();
759
gtk_box_pack_start (GTK_BOX (lookup_table_parent), separator, FALSE, FALSE, 0);
761
_lookup_table_window = gtk_window_new (GTK_WINDOW_POPUP);
762
gtk_widget_modify_bg (_lookup_table_window, GTK_STATE_NORMAL, &_normal_bg);
763
gtk_window_set_policy (GTK_WINDOW (_lookup_table_window), TRUE, TRUE, FALSE);
764
gtk_window_set_resizable (GTK_WINDOW (_lookup_table_window), FALSE);
765
gtk_widget_add_events (_lookup_table_window,GDK_BUTTON_PRESS_MASK);
766
gtk_widget_add_events (_lookup_table_window,GDK_BUTTON_RELEASE_MASK);
767
gtk_widget_add_events (_lookup_table_window,GDK_POINTER_MOTION_MASK);
768
g_signal_connect (G_OBJECT (_lookup_table_window), "button-press-event",
769
G_CALLBACK (ui_lookup_table_window_click_cb),
770
GINT_TO_POINTER (0));
771
g_signal_connect (G_OBJECT (_lookup_table_window), "button-release-event",
772
G_CALLBACK (ui_lookup_table_window_click_cb),
773
GINT_TO_POINTER (1));
774
gtk_container_set_border_width (GTK_CONTAINER (_lookup_table_window), 0);
776
frame = gtk_frame_new (0);
777
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
778
gtk_container_add (GTK_CONTAINER (_lookup_table_window), frame);
779
lookup_table_parent = frame;
782
//Vertical lookup table
783
if (_lookup_table_vertical) {
784
vbox = gtk_vbox_new (FALSE, 0);
785
gtk_container_add (GTK_CONTAINER (lookup_table_parent), vbox);
788
for (int i=0; i<SCIM_LOOKUP_TABLE_MAX_PAGESIZE; ++i) {
789
_lookup_table_items [i] = scim_string_view_new ();
790
if (_default_font_desc)
791
gtk_widget_modify_font (_lookup_table_items [i], _default_font_desc);
792
gtk_widget_modify_base (_lookup_table_items [i], GTK_STATE_NORMAL, &_normal_bg);
793
gtk_widget_modify_base (_lookup_table_items [i], GTK_STATE_ACTIVE, &_active_bg);
794
gtk_widget_modify_text (_lookup_table_items [i], GTK_STATE_NORMAL, &_normal_text);
795
gtk_widget_modify_text (_lookup_table_items [i], GTK_STATE_ACTIVE, &_active_text);
796
scim_string_view_set_width_chars (SCIM_STRING_VIEW (_lookup_table_items [i]), 80);
797
scim_string_view_set_has_frame (SCIM_STRING_VIEW (_lookup_table_items [i]), FALSE);
798
scim_string_view_set_forward_event (SCIM_STRING_VIEW (_lookup_table_items [i]), TRUE);
799
scim_string_view_set_auto_resize (SCIM_STRING_VIEW (_lookup_table_items [i]), TRUE);
800
scim_string_view_set_draw_cursor (SCIM_STRING_VIEW (_lookup_table_items [i]), FALSE);
801
scim_string_view_set_auto_move_cursor (SCIM_STRING_VIEW (_lookup_table_items [i]), FALSE);
802
g_signal_connect (G_OBJECT (_lookup_table_items [i]), "button-press-event",
803
G_CALLBACK (ui_lookup_table_vertical_click_cb),
804
GINT_TO_POINTER (i));
805
gtk_box_pack_start (GTK_BOX (vbox), _lookup_table_items [i], TRUE, TRUE, 0);
808
separator = gtk_hseparator_new ();
809
gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
811
hbox = gtk_hbox_new (FALSE, 0);
812
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
815
image = ui_create_down_icon ();
816
_lookup_table_down_button = gtk_button_new ();
817
gtk_container_add (GTK_CONTAINER (_lookup_table_down_button), image);
818
gtk_box_pack_end (GTK_BOX (hbox), _lookup_table_down_button, FALSE, FALSE, 0);
819
g_signal_connect (G_OBJECT (_lookup_table_down_button), "clicked",
820
G_CALLBACK (ui_lookup_table_down_button_click_cb),
824
image = ui_create_up_icon ();
825
_lookup_table_up_button = gtk_button_new ();
826
gtk_container_add (GTK_CONTAINER (_lookup_table_up_button), image);
827
gtk_box_pack_end (GTK_BOX (hbox), _lookup_table_up_button, FALSE, FALSE, 0);
828
g_signal_connect (G_OBJECT (_lookup_table_up_button), "clicked",
829
G_CALLBACK (ui_lookup_table_up_button_click_cb),
833
hbox = gtk_hbox_new (FALSE, 0);
834
gtk_container_add (GTK_CONTAINER (lookup_table_parent), hbox);
836
_lookup_table_items [0] = scim_string_view_new ();
837
if (_default_font_desc)
838
gtk_widget_modify_font (_lookup_table_items [0], _default_font_desc);
839
gtk_widget_modify_base (_lookup_table_items [0], GTK_STATE_NORMAL, &_normal_bg);
840
gtk_widget_modify_base (_lookup_table_items [0], GTK_STATE_ACTIVE, &_active_bg);
841
gtk_widget_modify_text (_lookup_table_items [0], GTK_STATE_NORMAL, &_normal_text);
842
gtk_widget_modify_text (_lookup_table_items [0], GTK_STATE_ACTIVE, &_active_text);
843
scim_string_view_set_forward_event (SCIM_STRING_VIEW (_lookup_table_items [0]), TRUE);
844
scim_string_view_set_auto_resize (SCIM_STRING_VIEW (_lookup_table_items [0]), TRUE);
845
scim_string_view_set_has_frame (SCIM_STRING_VIEW (_lookup_table_items [0]), FALSE);
846
scim_string_view_set_draw_cursor (SCIM_STRING_VIEW (_lookup_table_items [0]), FALSE);
847
scim_string_view_set_auto_move_cursor (SCIM_STRING_VIEW (_lookup_table_items [0]), FALSE);
848
g_signal_connect (G_OBJECT (_lookup_table_items [0]), "move_cursor",
849
G_CALLBACK (ui_lookup_table_horizontal_click_cb),
851
gtk_box_pack_start (GTK_BOX (hbox), _lookup_table_items [0], TRUE, TRUE, 0);
853
separator = gtk_vseparator_new ();
854
gtk_box_pack_start (GTK_BOX (hbox), separator, FALSE, FALSE, 0);
857
image = ui_create_left_icon ();
858
_lookup_table_up_button = gtk_button_new ();
859
gtk_container_add (GTK_CONTAINER (_lookup_table_up_button), image);
861
gtk_box_pack_start (GTK_BOX (hbox), _lookup_table_up_button, FALSE, FALSE, 0);
862
g_signal_connect (G_OBJECT (_lookup_table_up_button), "clicked",
863
G_CALLBACK (ui_lookup_table_up_button_click_cb),
867
image = ui_create_right_icon ();
868
_lookup_table_down_button = gtk_button_new ();
869
gtk_container_add (GTK_CONTAINER (_lookup_table_down_button), image);
871
gtk_box_pack_start (GTK_BOX (hbox), _lookup_table_down_button, FALSE, FALSE, 0);
873
g_signal_connect (G_OBJECT (_lookup_table_down_button), "clicked",
874
G_CALLBACK (ui_lookup_table_down_button_click_cb),
878
gtk_button_set_relief (GTK_BUTTON (_lookup_table_up_button), GTK_RELIEF_NONE);
879
gtk_widget_modify_bg (_lookup_table_up_button, GTK_STATE_ACTIVE, &_normal_bg);
880
gtk_widget_modify_bg (_lookup_table_up_button, GTK_STATE_INSENSITIVE, &_normal_bg);
881
gtk_widget_modify_bg (_lookup_table_up_button, GTK_STATE_PRELIGHT, &_normal_bg);
883
gtk_button_set_relief (GTK_BUTTON (_lookup_table_down_button), GTK_RELIEF_NONE);
884
gtk_widget_modify_bg (_lookup_table_down_button, GTK_STATE_ACTIVE, &_normal_bg);
885
gtk_widget_modify_bg (_lookup_table_down_button, GTK_STATE_INSENSITIVE, &_normal_bg);
886
gtk_widget_modify_bg (_lookup_table_down_button, GTK_STATE_PRELIGHT, &_normal_bg);
888
if (!_lookup_table_embedded)
889
gtk_window_move (GTK_WINDOW (_lookup_table_window), ui_screen_width (), ui_screen_height ());
891
gtk_widget_show_all (_lookup_table_window);
892
gtk_widget_hide (_lookup_table_window);
895
//Create toolbar window
901
_toolbar_window = gtk_window_new (GTK_WINDOW_POPUP);
902
gtk_window_set_policy (GTK_WINDOW (_toolbar_window), TRUE, TRUE, FALSE);
903
gtk_window_set_resizable (GTK_WINDOW (_toolbar_window), FALSE);
904
gtk_widget_add_events (_toolbar_window,GDK_BUTTON_PRESS_MASK);
905
gtk_widget_add_events (_toolbar_window,GDK_BUTTON_RELEASE_MASK);
906
gtk_widget_add_events (_toolbar_window,GDK_POINTER_MOTION_MASK);
907
g_signal_connect (G_OBJECT (_toolbar_window), "button-press-event",
908
G_CALLBACK (ui_toolbar_window_click_cb),
909
GINT_TO_POINTER (0));
910
g_signal_connect (G_OBJECT (_toolbar_window), "button-release-event",
911
G_CALLBACK (ui_toolbar_window_click_cb),
912
GINT_TO_POINTER (1));
914
frame = gtk_frame_new (0);
915
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
916
gtk_container_add (GTK_CONTAINER (_toolbar_window), frame);
918
hbox = gtk_hbox_new (FALSE, 0);
919
gtk_container_add (GTK_CONTAINER (frame), hbox);
921
//New trademark pixmap
922
image = ui_create_trademark_icon ();
923
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
926
if (_toolbar_show_stick_icon) {
927
image = ui_create_stick_icon (_window_sticked);
928
_window_stick_button = gtk_button_new ();
929
gtk_button_set_relief (GTK_BUTTON (_window_stick_button), GTK_RELIEF_NONE);
930
gtk_container_add (GTK_CONTAINER (_window_stick_button), image);
931
gtk_box_pack_start (GTK_BOX (hbox), _window_stick_button, TRUE, TRUE, 0);
932
g_signal_connect (G_OBJECT (_window_stick_button), "clicked",
933
G_CALLBACK (ui_window_stick_button_click_cb),
938
if (_toolbar_show_factory_icon || _toolbar_show_factory_name) {
939
_factory_button = gtk_button_new ();
940
gtk_button_set_relief (GTK_BUTTON (_factory_button), GTK_RELIEF_NONE);
941
gtk_box_pack_start (GTK_BOX (hbox), _factory_button, TRUE, TRUE, 0);
942
g_signal_connect (G_OBJECT (_factory_button), "button-release-event",
943
G_CALLBACK (ui_factory_button_click_cb),
947
// Put all properties here
948
_client_properties_area = gtk_hbox_new (FALSE, 0);
949
gtk_box_pack_start (GTK_BOX (hbox), _client_properties_area, TRUE, TRUE, 0);
950
gtk_widget_show (_client_properties_area);
953
if (_toolbar_show_menu_icon) {
954
image = ui_create_menu_icon ();
955
_menu_button = gtk_button_new ();
956
gtk_button_set_relief (GTK_BUTTON (_menu_button), GTK_RELIEF_NONE);
957
gtk_container_add (GTK_CONTAINER (_menu_button), image);
958
gtk_box_pack_start (GTK_BOX (hbox), _menu_button, TRUE, TRUE, 0);
959
g_signal_connect (G_OBJECT (_menu_button), "clicked",
960
G_CALLBACK (ui_menu_button_click_cb),
965
if (_toolbar_show_help_icon) {
966
image = ui_create_help_icon ();
967
_help_button = gtk_button_new ();
968
gtk_button_set_relief (GTK_BUTTON (_help_button), GTK_RELIEF_NONE);
969
gtk_container_add (GTK_CONTAINER (_help_button), image);
970
gtk_box_pack_start (GTK_BOX (hbox), _help_button, TRUE, TRUE, 0);
971
g_signal_connect (G_OBJECT (_help_button), "clicked",
972
G_CALLBACK (ui_help_button_click_cb),
976
gtk_window_move (GTK_WINDOW (_toolbar_window), ui_screen_width (), ui_screen_height ());
978
gtk_widget_show_all (_toolbar_window);
979
gtk_widget_hide (_toolbar_window);
981
ui_settle_toolbar_window ();
984
// Create help window
986
_help_dialog = gtk_dialog_new_with_buttons (_("SCIM Help"),
993
g_signal_connect_swapped (GTK_OBJECT (_help_dialog),
995
G_CALLBACK (gtk_widget_hide),
996
GTK_OBJECT (_help_dialog));
998
g_signal_connect_swapped (GTK_OBJECT (_help_dialog),
1000
G_CALLBACK (gtk_widget_hide_on_delete),
1001
GTK_OBJECT (_help_dialog));
1003
_help_scroll = gtk_scrolled_window_new (NULL, NULL);
1004
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (_help_scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1005
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (_help_dialog)->vbox), _help_scroll, TRUE, TRUE, 0);
1006
gtk_widget_show (_help_scroll);
1008
_help_area = gtk_label_new ("");
1009
gtk_label_set_justify (GTK_LABEL (_help_area), GTK_JUSTIFY_LEFT);
1010
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (_help_scroll), _help_area);
1011
gtk_widget_show (_help_area);
1014
#if ENABLE_TRAY_ICON
1017
if (_show_tray_icon)
1018
ui_create_tray_icon_when_idle (0);
1022
//Settle input/lookup windows to default position
1024
uint32 spot_x, spot_y;
1026
spot_x = ui_screen_width () / 2 - 64;
1027
spot_y = ui_screen_height () * 3 / 4;
1028
gtk_window_move (GTK_WINDOW (_input_window), spot_x, spot_y);
1030
if (!_lookup_table_embedded)
1031
gtk_window_move (GTK_WINDOW (_lookup_table_window), spot_x, spot_y + 32);
1034
//Init timeout callback
1035
if (_toolbar_hide_timeout != 0) {
1036
g_source_remove (_toolbar_hide_timeout);
1037
_toolbar_hide_timeout = 0;
1040
if (_toolbar_always_show && _toolbar_hide_timeout_max > 0) {
1041
_toolbar_hide_timeout = g_timeout_add (1000, ui_hide_window_timeout_cb, NULL);
1042
g_signal_connect (G_OBJECT (_toolbar_window), "enter-notify-event",
1043
G_CALLBACK (ui_toolbar_window_crossing_cb),
1044
GINT_TO_POINTER (0));
1045
g_signal_connect (G_OBJECT (_toolbar_window), "leave-notify-event",
1046
G_CALLBACK (ui_toolbar_window_crossing_cb),
1047
GINT_TO_POINTER (1));
1050
// Init the tooltips
1052
_tooltips = gtk_tooltips_new ();
1054
gtk_tooltips_set_delay (_tooltips, 1000);
1056
if (_window_stick_button)
1057
gtk_tooltips_set_tip (_tooltips, _window_stick_button,
1058
_("Stick/unstick the input window and the toolbar."),
1062
gtk_tooltips_set_tip (_tooltips, _help_button,
1063
_("Show a brief help about SCIM and the current input method."),
1067
gtk_tooltips_set_tip (_tooltips, _menu_button,
1068
_("Show command menu."),
1072
#ifdef GDK_WINDOWING_X11
1073
// Add an event filter function to observe X root window's properties.
1074
GdkWindow *root_window = gdk_get_default_root_window ();
1075
#if GDK_MULTIHEAD_SAFE
1076
if (_current_screen)
1077
root_window = gdk_screen_get_root_window (_current_screen);
1079
gdk_window_set_events (root_window, (GdkEventMask)GDK_PROPERTY_NOTIFY);
1080
gdk_window_add_filter (root_window, ui_event_filter, NULL);
1083
_ui_initialized = true;
1087
ui_settle_input_window (bool relative, bool force)
1089
SCIM_DEBUG_MAIN (2) << " Settle input window...\n";
1091
if (_window_sticked) {
1093
gtk_window_move (GTK_WINDOW (_input_window), _input_window_x, _input_window_y);
1098
gint spot_x, spot_y;
1100
gtk_widget_size_request (_input_window, &ws);
1103
spot_x = _spot_location_x;
1104
spot_y = _spot_location_y;
1106
spot_x = _input_window_x;
1107
spot_y = _input_window_y;
1110
if (spot_x < 0) spot_x = 0;
1111
if (spot_y < 0) spot_y = 0;
1113
if (spot_x + ws.width > ui_screen_width () - 4)
1114
spot_x = ui_screen_width () - ws.width - 4;
1115
if (spot_y + ws.height + 8 > ui_screen_height () - 4)
1116
spot_y = ui_screen_height () - ws.height - 4;
1118
if (spot_x != _input_window_x || spot_y != _input_window_y || force) {
1119
gtk_window_move (GTK_WINDOW (_input_window), spot_x, spot_y);
1120
_input_window_x = spot_x;
1121
_input_window_y = spot_y;
1126
ui_settle_lookup_table_window(bool force)
1128
SCIM_DEBUG_MAIN (2) << " Settle lookup table window...\n";
1130
if (_lookup_table_embedded)
1133
if (_window_sticked) {
1135
gtk_window_move (GTK_WINDOW (_lookup_table_window), _lookup_table_window_x, _lookup_table_window_y);
1144
gtk_widget_size_request (_input_window, &iws);
1145
gtk_widget_size_request (_lookup_table_window, &ws);
1147
pos_x = _input_window_x;
1148
pos_y = _input_window_y + iws.height + 8;
1150
if (pos_x + ws.width > ui_screen_width () - 8) {
1151
pos_x = ui_screen_width () - ws.width - 8;
1154
if (pos_y + ws.height > ui_screen_height () - 8) {
1155
pos_y = ui_screen_height () - ws.height - 40;
1158
// input window and lookup table window are overlapped.
1159
if (pos_y < _input_window_y + iws.height && pos_y + ws.height > _input_window_y) {
1160
pos_y = _input_window_y - ws.height - 8;
1163
if (_lookup_table_window_x != pos_x || _lookup_table_window_y != pos_y || force) {
1164
gtk_window_move (GTK_WINDOW (_lookup_table_window), pos_x, pos_y);
1165
_lookup_table_window_x = pos_x;
1166
_lookup_table_window_y = pos_y;
1171
ui_settle_toolbar_window (bool force)
1173
SCIM_DEBUG_MAIN (2) << " Settle toolbar window...\n";
1175
if (_window_sticked) {
1177
gtk_window_move (GTK_WINDOW (_toolbar_window), _toolbar_window_x, _toolbar_window_y);
1181
gint workarea_x, workarea_y, workarea_width, workarea_height;
1182
ui_get_workarea (workarea_x, workarea_y, workarea_width, workarea_height);
1187
gtk_widget_size_request (_toolbar_window, &ws);
1189
pos_x = _config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_X),
1190
workarea_x + workarea_width - ws.width);
1191
pos_y = _config->read (String (SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_Y),
1192
workarea_y + workarea_height - ws.height);
1193
if (pos_x == -1 && pos_y == -1) {
1194
pos_x = workarea_x + workarea_width - ws.width;
1195
pos_y = workarea_y + workarea_height - ws.height;
1198
if (_toolbar_auto_snap) {
1199
if ((ui_screen_width () - (pos_x + ws.width)) < pos_x)
1200
pos_x = ui_screen_width () - ws.width;
1203
} else if (pos_x + ws.width > ui_screen_width ()) {
1204
pos_x = ui_screen_width () - ws.width;
1205
} else if (pos_x < 0) {
1209
if (pos_y + ws.height > ui_screen_height ())
1210
pos_y = ui_screen_height () - ws.height;
1214
if (_toolbar_window_x != pos_x || _toolbar_window_y != pos_y || force) {
1215
gtk_window_move (GTK_WINDOW (_toolbar_window), pos_x, pos_y);
1216
_toolbar_window_x = pos_x;
1217
_toolbar_window_y = pos_y;
1222
ui_screen_width (void)
1224
#if GDK_MULTIHEAD_SAFE
1225
if (_current_screen)
1226
return gdk_screen_get_width (_current_screen);
1228
return gdk_screen_width ();
1232
ui_screen_height (void)
1234
#if GDK_MULTIHEAD_SAFE
1235
if (_current_screen)
1236
return gdk_screen_get_height (_current_screen);
1238
return gdk_screen_height ();
1242
ui_get_workarea (int &x, int &y, int &width, int &height)
1244
static GdkAtom net_current_desktop_atom = gdk_atom_intern ("_NET_CURRENT_DESKTOP", TRUE);;
1245
static GdkAtom net_workarea_atom = gdk_atom_intern ("_NET_WORKAREA", TRUE);
1246
GdkWindow *root_window = gdk_get_default_root_window ();
1248
gint format, length, current_desktop = 0;
1251
#if GDK_MULTIHEAD_SAFE
1252
if (_current_screen)
1253
root_window = gdk_screen_get_root_window (_current_screen);
1258
width = ui_screen_width ();
1259
height = ui_screen_height ();
1261
if (net_current_desktop_atom != GDK_NONE) {
1262
gboolean found = gdk_property_get (root_window,
1263
net_current_desktop_atom, GDK_NONE, 0, G_MAXLONG, FALSE,
1264
&atom_ret, &format, &length, &data);
1265
if (found && format == 32 && length / sizeof(glong) > 0)
1266
current_desktop = ((glong*)data)[0];
1271
if (net_workarea_atom != GDK_NONE) {
1272
gboolean found = gdk_property_get (root_window,
1273
net_workarea_atom, GDK_NONE, 0, G_MAXLONG, FALSE,
1274
&atom_ret, &format, &length, &data);
1275
if (found && format == 32 && length / sizeof(glong) >= (current_desktop + 1) * 4) {
1276
x = ((glong*)data)[current_desktop * 4];
1277
y = ((glong*)data)[current_desktop * 4 + 1];
1278
width = ((glong*)data)[current_desktop * 4 + 2];
1279
height = ((glong*)data)[current_desktop * 4 + 3];
1286
#if GDK_MULTIHEAD_SAFE
1288
ui_switch_screen (GdkScreen *screen)
1291
if (_input_window) {
1292
gtk_window_set_screen (GTK_WINDOW (_input_window), screen);
1294
_input_window_x = ui_screen_width ();
1295
_input_window_y = ui_screen_height ();
1297
gtk_window_move (GTK_WINDOW (_input_window), _input_window_x, _input_window_y);
1300
if (_toolbar_window) {
1301
gtk_window_set_screen (GTK_WINDOW (_toolbar_window), screen);
1302
ui_settle_toolbar_window ();
1305
if (!_lookup_table_embedded && _lookup_table_window) {
1306
gtk_window_set_screen (GTK_WINDOW (_lookup_table_window), screen);
1308
_lookup_table_window_x = ui_screen_width ();
1309
_lookup_table_window_y = ui_screen_height ();
1311
gtk_window_move (GTK_WINDOW (_lookup_table_window), _lookup_table_window_x, _lookup_table_window_y);
1314
#if ENABLE_TRAY_ICON
1315
// if (_tray_icon) {
1316
// gtk_window_set_screen (GTK_WINDOW (_tray_icon), screen);
1321
gtk_window_set_screen (GTK_WINDOW (_help_dialog), screen);
1324
#ifdef GDK_WINDOWING_X11
1325
GdkWindow *root_window = gdk_get_default_root_window ();
1326
if (_current_screen)
1327
root_window = gdk_screen_get_root_window (_current_screen);
1328
gdk_window_set_events (root_window, (GdkEventMask)GDK_PROPERTY_NOTIFY);
1329
gdk_window_add_filter (root_window, ui_event_filter, NULL);
1332
ui_settle_input_window ();
1333
ui_settle_lookup_table_window ();
1334
ui_settle_toolbar_window ();
1339
#if ENABLE_TRAY_ICON
1341
// ui_tray_icon_expose_event_cb (GtkWidget *widget, GdkEventExpose *event)
1343
// gdk_window_clear_area (widget->window, event->area.x, event->area.y,
1344
// event->area.width, event->area.height);
1349
// ui_tray_icon_style_set_cb (GtkWidget *widget, GtkStyle *previous_style)
1351
// gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
1355
// ui_tray_icon_realize_cb (GtkWidget *widget)
1357
// if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget))
1360
// gtk_widget_set_app_paintable (widget, TRUE);
1361
// gtk_widget_set_double_buffered (widget, FALSE);
1362
// gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
1363
// g_signal_connect (widget, "expose_event",
1364
// G_CALLBACK (ui_tray_icon_expose_event_cb), NULL);
1365
// g_signal_connect_after (widget, "style_set",
1366
// G_CALLBACK (ui_tray_icon_style_set_cb), NULL);
1370
ui_create_tray_icon_when_idle (gpointer data)
1374
_tray_icon = gtk_status_icon_new_from_file (SCIM_KEYBOARD_ICON_FILE);
1375
// g_signal_connect (G_OBJECT (_tray_icon), "realize",
1376
// G_CALLBACK (ui_tray_icon_realize_cb), NULL);
1378
// _tray_icon_destroy_signal_id =
1379
// g_signal_connect (G_OBJECT (_tray_icon), "destroy",
1380
// G_CALLBACK (ui_tray_icon_destroy_cb),
1383
// image = ui_create_icon (SCIM_KEYBOARD_ICON_FILE,
1389
// _tray_icon_factory_button = gtk_event_box_new ();
1390
// g_signal_connect (G_OBJECT (_tray_icon_factory_button), "realize",
1391
// G_CALLBACK (ui_tray_icon_realize_cb), NULL);
1392
// gtk_container_add (GTK_CONTAINER (_tray_icon_factory_button), image);
1393
// gtk_container_add (GTK_CONTAINER (_tray_icon), _tray_icon_factory_button);
1396
// g_signal_connect (G_OBJECT (_tray_icon_factory_button), "button-release-event",
1397
// G_CALLBACK (ui_factory_button_click_cb),
1400
g_signal_connect (G_OBJECT (_tray_icon), "popup-menu",
1401
G_CALLBACK (ui_tray_icon_popup_menu_cb),
1404
g_signal_connect (G_OBJECT (_tray_icon), "activate",
1405
G_CALLBACK (ui_tray_icon_activate_cb),
1408
gtk_status_icon_set_visible (_tray_icon, TRUE);
1415
ui_scale_pixbuf (GdkPixbuf *pixbuf,
1420
if (gdk_pixbuf_get_width (pixbuf) != width ||
1421
gdk_pixbuf_get_height (pixbuf) != height) {
1422
GdkPixbuf *dest = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
1423
g_object_unref (pixbuf);
1431
ui_create_label (const String &name,
1432
const String &iconfile,
1434
bool show_icon_only,
1437
GtkWidget * hbox = gtk_hbox_new (FALSE, 0);
1438
GtkWidget * label = gtk_label_new (name.c_str ());
1442
if (_default_font_desc)
1443
gtk_widget_modify_font (label, _default_font_desc);
1445
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
1447
GtkWidget *icon = ui_create_icon (iconfile,
1454
gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
1455
if (!show_icon_only)
1456
gtk_box_set_spacing (GTK_BOX (hbox), 4);
1459
if (!show_icon_only || !icon)
1460
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1462
gtk_widget_destroy (label);
1464
gtk_widget_show_all (hbox);
1470
ui_create_icon (const String &iconfile,
1476
String path = iconfile;
1477
GdkPixbuf *pixbuf = 0;
1479
if (path.length ()) {
1480
// Not a absolute path, prepend SCIM_ICONDIR
1481
if (path [0] != SCIM_PATH_DELIM)
1482
path = String (SCIM_ICONDIR) + String (SCIM_PATH_DELIM_STRING) + path;
1484
pixbuf = gdk_pixbuf_new_from_file (path.c_str (), 0);
1487
if (!pixbuf && xpm) {
1488
pixbuf = gdk_pixbuf_new_from_xpm_data (xpm);
1491
if (!pixbuf && force_create) {
1492
if (width <= 0 || height <= 0)
1495
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, true, 8, width, height);
1500
gdk_pixbuf_fill (pixbuf, 0);
1504
if (width <= 0) width = gdk_pixbuf_get_width (pixbuf);
1505
if (height <= 0) height = gdk_pixbuf_get_height (pixbuf);
1507
pixbuf = ui_scale_pixbuf (pixbuf, width, height);
1509
GtkWidget *icon = gtk_image_new_from_pixbuf (pixbuf);
1510
gtk_widget_show (icon);
1512
gdk_pixbuf_unref (pixbuf);
1520
ui_create_trademark_icon (void)
1522
return ui_create_icon (SCIM_TRADEMARK_ICON_FILE,
1523
(const char **) trademark_xpm,
1524
TOOLBAR_ICON_SIZE + 4,
1525
TOOLBAR_ICON_SIZE + 4);
1529
ui_create_stick_icon (bool sticked)
1531
return ui_create_icon ((sticked ? SCIM_PIN_DOWN_ICON_FILE : SCIM_PIN_UP_ICON_FILE),
1532
(const char **) (sticked ? pin_down_xpm : pin_up_xpm),
1538
ui_create_help_icon (void)
1540
return ui_create_icon (SCIM_HELP_ICON_FILE,
1541
(const char **) help_xpm,
1547
ui_create_menu_icon (void)
1549
return ui_create_icon (SCIM_MENU_ICON_FILE,
1550
(const char **) menu_xpm,
1556
ui_create_up_icon (void)
1558
return ui_create_icon (SCIM_UP_ICON_FILE,
1559
(const char **) up_xpm,
1565
ui_create_left_icon (void)
1567
return ui_create_icon (SCIM_LEFT_ICON_FILE,
1568
(const char **) left_xpm,
1574
ui_create_right_icon (void)
1576
return ui_create_icon (SCIM_RIGHT_ICON_FILE,
1577
(const char **) right_xpm,
1583
ui_create_down_icon (void)
1585
return ui_create_icon (SCIM_DOWN_ICON_FILE,
1586
(const char **) down_xpm,
1592
ui_create_factory_menu_entry (const PanelFactoryInfo &info,
1599
GtkWidget *menu_item;
1600
GtkWidget *icon_image;
1601
String text, tooltip;
1603
if ((!show_lang && show_name) || (show_lang && !show_name && (info.lang == "C" || info.lang == "~other"))) {
1606
} else if (show_lang && !show_name) {
1607
text = scim_get_language_name (info.lang);
1608
tooltip = info.name;
1610
text = scim_get_language_name (info.lang) + " - " + info.name;
1614
menu_item = gtk_image_menu_item_new_with_label (text.c_str ());
1615
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
1616
icon_image = ui_create_icon (info.icon, NULL, width, height, false);
1618
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), icon_image);
1620
g_signal_connect (G_OBJECT (menu_item), "activate",
1621
G_CALLBACK (ui_factory_menu_activate_cb),
1622
GINT_TO_POINTER ((gint)id));
1623
gtk_widget_show (menu_item);
1625
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1628
gtk_tooltips_set_tip (_tooltips, menu_item, tooltip.c_str (), NULL);
1633
/* Implementation of callback functions */
1635
ui_preedit_area_move_cursor_cb (ScimStringView *view,
1638
SCIM_DEBUG_MAIN (3) << " ui_preedit_area_move_cursor_cb...\n";
1640
_panel_agent->move_preedit_caret (position);
1644
ui_help_button_click_cb (GtkButton *button,
1647
SCIM_DEBUG_MAIN (3) << " ui_help_button_click_cb...\n";
1649
if (GTK_WIDGET_VISIBLE (_help_dialog)) {
1650
gtk_widget_hide (_help_dialog);
1652
action_request_help ();
1657
ui_menu_button_click_cb (GtkButton *button,
1660
SCIM_DEBUG_MAIN (3) << " ui_menu_button_click_cb...\n";
1662
struct timeval cur_time;
1663
gettimeofday (&cur_time, 0);
1665
if (cur_time.tv_sec < _last_menu_deactivate_time.tv_sec ||
1666
(cur_time.tv_sec == _last_menu_deactivate_time.tv_sec &&
1667
cur_time.tv_usec < _last_menu_deactivate_time.tv_usec + 200000))
1670
action_show_command_menu ();
1674
ui_factory_button_click_cb (GtkWidget *button,
1678
SCIM_DEBUG_MAIN (3) << " ui_factory_button_click_cb...\n";
1680
GdkEventButton *bevent = (GdkEventButton *) event;
1682
struct timeval cur_time;
1683
gettimeofday (&cur_time, 0);
1685
if (cur_time.tv_sec < _last_menu_deactivate_time.tv_sec ||
1686
(cur_time.tv_sec == _last_menu_deactivate_time.tv_sec &&
1687
cur_time.tv_usec < _last_menu_deactivate_time.tv_usec + 200000))
1690
if (bevent->button <= 1)
1691
_panel_agent->request_factory_menu ();
1693
action_show_command_menu ();
1699
ui_tray_icon_popup_menu_cb (GtkStatusIcon *status_icon, guint button,
1700
guint activate_time, gpointer user_data)
1702
action_show_command_menu ();
1706
ui_tray_icon_activate_cb (GtkStatusIcon *status_icon, gpointer user_data)
1708
_panel_agent->request_factory_menu ();
1712
ui_factory_menu_activate_cb (GtkMenuItem *item,
1715
int id = GPOINTER_TO_INT (user_data);
1717
if (id >= 0 && id < (int) _factory_menu_uuids.size ())
1718
_panel_agent->change_factory (_factory_menu_uuids [id]);
1720
_panel_agent->change_factory ("");
1724
ui_factory_menu_deactivate_cb (GtkMenuItem *item,
1727
_factory_menu_activated = false;
1728
gettimeofday (&_last_menu_deactivate_time, 0);
1732
ui_lookup_table_vertical_click_cb (GtkWidget *item,
1733
GdkEventButton *event,
1736
SCIM_DEBUG_MAIN (3) << " ui_lookup_table_vertical_click_cb...\n";
1738
_panel_agent->select_candidate ((uint32)GPOINTER_TO_INT (user_data));
1744
ui_lookup_table_horizontal_click_cb (GtkWidget *item,
1747
SCIM_DEBUG_MAIN (3) << " ui_lookup_table_horizontal_click_cb...\n";
1749
int *index = _lookup_table_index;
1750
int pos = (int) position;
1752
for (int i=0; i<SCIM_LOOKUP_TABLE_MAX_PAGESIZE && index [i] >= 0; ++i) {
1753
if (pos >= index [i] && pos < index [i+1]) {
1754
_panel_agent->select_candidate ((uint32) i);
1761
ui_lookup_table_up_button_click_cb (GtkButton *button,
1764
SCIM_DEBUG_MAIN (3) << " ui_lookup_table_up_button_click_cb...\n";
1766
_panel_agent->lookup_table_page_up ();
1770
ui_lookup_table_down_button_click_cb (GtkButton *button,
1773
SCIM_DEBUG_MAIN (3) << " ui_lookup_table_down_button_click_cb...\n";
1775
_panel_agent->lookup_table_page_down ();
1779
ui_window_stick_button_click_cb (GtkButton *button,
1782
action_toggle_window_stick ();
1786
ui_input_window_motion_cb (GtkWidget *window,
1787
GdkEventMotion *event,
1792
if ((event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) != 0 &&
1793
_input_window_draging) {
1794
gtk_window_get_position (GTK_WINDOW (window), &pos_x, &pos_y);
1795
gtk_window_move (GTK_WINDOW (window),
1796
pos_x + ((gint) event->x_root - _input_window_drag_x),
1797
pos_y + ((gint) event->y_root - _input_window_drag_y));
1799
_input_window_drag_x = (gint) event->x_root;
1800
_input_window_drag_y = (gint) event->y_root;
1808
ui_input_window_click_cb (GtkWidget *window,
1809
GdkEventButton *event,
1812
int click_type = GPOINTER_TO_INT (user_data);
1813
static gulong motion_handler;
1816
if (click_type == 0) {
1817
if (_input_window_draging)
1820
// Connection pointer motion handler to this window.
1821
motion_handler = g_signal_connect (G_OBJECT (window), "motion-notify-event",
1822
G_CALLBACK (ui_input_window_motion_cb),
1825
_input_window_draging = TRUE;
1826
_input_window_drag_x = (gint) event->x_root;
1827
_input_window_drag_y = (gint) event->y_root;
1829
cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
1831
// Grab the cursor to prevent losing events.
1832
gdk_pointer_grab (window->window, TRUE,
1833
(GdkEventMask) (GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK),
1834
NULL, cursor, event->time);
1835
gdk_cursor_unref (cursor);
1837
} else if (click_type == 1) {
1838
if (!_input_window_draging)
1841
g_signal_handler_disconnect (G_OBJECT (window), motion_handler);
1842
gdk_pointer_ungrab (event->time);
1843
_input_window_draging = FALSE;
1845
gtk_window_get_position (GTK_WINDOW (window), &_input_window_x, &_input_window_y);
1854
ui_toolbar_window_crossing_cb (GtkWidget *window,
1855
GdkEventCrossing *event,
1858
if (!_toolbar_always_show || _panel_is_on || _toolbar_window_draging)
1861
int crossing_type = GPOINTER_TO_INT (user_data);
1863
// 0 == enter, otherwise leave
1864
if (crossing_type == 0) {
1865
if (_toolbar_hidden) {
1866
if (_window_stick_button)
1867
gtk_widget_show (_window_stick_button);
1869
if (_factory_button)
1870
gtk_widget_show (_factory_button);
1872
if (_client_properties_area)
1873
gtk_widget_show (_client_properties_area);
1876
gtk_widget_show (_menu_button);
1879
gtk_widget_show (_help_button);
1881
_toolbar_hidden = false;
1882
ui_settle_toolbar_window ();
1884
_toolbar_should_hide = false;
1886
_toolbar_should_hide = true;
1893
ui_toolbar_window_motion_cb (GtkWidget *window,
1894
GdkEventMotion *event,
1898
if ((event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) != 0 &&
1899
_toolbar_window_draging) {
1900
gtk_window_get_position (GTK_WINDOW (window), &pos_x, &pos_y);
1901
gtk_window_move (GTK_WINDOW (window),
1902
pos_x + ((gint) event->x_root - _toolbar_window_drag_x),
1903
pos_y + ((gint) event->y_root - _toolbar_window_drag_y));
1905
_toolbar_window_drag_x = (gint) event->x_root;
1906
_toolbar_window_drag_y = (gint) event->y_root;
1914
ui_toolbar_window_click_cb (GtkWidget *window,
1915
GdkEventButton *event,
1918
int click_type = GPOINTER_TO_INT (user_data);
1919
static gulong motion_handler;
1922
if (click_type == 0 && event->button <= 1) {
1923
if (_toolbar_window_draging)
1926
// Connection pointer motion handler to this window.
1927
motion_handler = g_signal_connect (G_OBJECT (window), "motion-notify-event",
1928
G_CALLBACK (ui_toolbar_window_motion_cb),
1931
_toolbar_window_draging = TRUE;
1932
_toolbar_window_drag_x = (gint) event->x_root;
1933
_toolbar_window_drag_y = (gint) event->y_root;
1935
cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
1937
// Grab the cursor to prevent losing events.
1938
gdk_pointer_grab (window->window, TRUE,
1939
(GdkEventMask) (GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK),
1940
NULL, cursor, event->time);
1941
gdk_cursor_unref (cursor);
1943
} else if (click_type == 1 && event->button <= 1) {
1944
if (!_toolbar_window_draging)
1947
g_signal_handler_disconnect (G_OBJECT (window), motion_handler);
1948
gdk_pointer_ungrab (event->time);
1949
_toolbar_window_draging = FALSE;
1953
gtk_window_get_position (GTK_WINDOW (window), &pos_x, &pos_y);
1955
if (!_config.null () &&
1956
(_toolbar_window_x != pos_x || _toolbar_window_y != pos_y)) {
1958
SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_X, pos_x);
1960
SCIM_CONFIG_PANEL_GTK_TOOLBAR_POS_Y, pos_y);
1963
_toolbar_window_x = pos_x;
1964
_toolbar_window_y = pos_y;
1967
} else if (click_type == 1 && event->button > 1) {
1968
action_show_command_menu ();
1975
ui_lookup_table_window_motion_cb (GtkWidget *window,
1976
GdkEventMotion *event,
1980
if ((event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) != 0 &&
1981
_lookup_table_window_draging) {
1982
gtk_window_get_position (GTK_WINDOW (window), &pos_x, &pos_y);
1983
gtk_window_move (GTK_WINDOW (window),
1984
pos_x + ((gint) event->x_root - _lookup_table_window_drag_x),
1985
pos_y + ((gint) event->y_root - _lookup_table_window_drag_y));
1987
_lookup_table_window_drag_x = (gint) event->x_root;
1988
_lookup_table_window_drag_y = (gint) event->y_root;
1996
ui_lookup_table_window_click_cb (GtkWidget *window,
1997
GdkEventButton *event,
2000
int click_type = GPOINTER_TO_INT (user_data);
2001
static gulong motion_handler;
2004
if (click_type == 0) {
2005
if (_lookup_table_window_draging)
2008
// Connection pointer motion handler to this window.
2009
motion_handler = g_signal_connect (G_OBJECT (window), "motion-notify-event",
2010
G_CALLBACK (ui_lookup_table_window_motion_cb),
2013
_lookup_table_window_draging = TRUE;
2014
_lookup_table_window_drag_x = (gint) event->x_root;
2015
_lookup_table_window_drag_y = (gint) event->y_root;
2017
cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
2019
// Grab the cursor to prevent losing events.
2020
gdk_pointer_grab (window->window, TRUE,
2021
(GdkEventMask) (GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK),
2022
NULL, cursor, event->time);
2023
gdk_cursor_unref (cursor);
2025
} else if (click_type == 1) {
2026
if (!_lookup_table_window_draging)
2029
g_signal_handler_disconnect (G_OBJECT (window), motion_handler);
2030
gdk_pointer_ungrab (event->time);
2031
_lookup_table_window_draging = FALSE;
2033
gtk_window_get_position (GTK_WINDOW (window), &_lookup_table_window_x, &_lookup_table_window_y);
2042
ui_hide_window_timeout_cb (gpointer data)
2044
gdk_threads_enter ();
2046
if (!_toolbar_always_show) {
2047
gdk_threads_leave ();
2051
if (!_toolbar_should_hide || _panel_is_on ||
2052
_toolbar_window_draging || _toolbar_hidden ||
2053
ui_any_menu_activated ()) {
2054
_toolbar_hide_timeout_count = 0;
2055
gdk_threads_leave ();
2059
_toolbar_hide_timeout_count ++;
2061
if (_toolbar_hide_timeout_count > _toolbar_hide_timeout_max) {
2062
_toolbar_hide_timeout_count = 0;
2065
gtk_widget_hide (_help_button);
2068
gtk_widget_hide (_menu_button);
2070
if (_client_properties_area)
2071
gtk_widget_hide (_client_properties_area);
2073
if (_factory_button)
2074
gtk_widget_hide (_factory_button);
2076
if (_window_stick_button)
2077
gtk_widget_hide (_window_stick_button);
2079
_toolbar_hidden = true;
2080
ui_settle_toolbar_window ();
2083
gdk_threads_leave ();
2088
ui_can_hide_input_window (void)
2090
if (!_panel_is_on) return true;
2092
if (GTK_WIDGET_VISIBLE (_preedit_area) ||
2093
GTK_WIDGET_VISIBLE (_aux_area) ||
2094
(_lookup_table_embedded && GTK_WIDGET_VISIBLE (_lookup_table_window)))
2100
ui_any_menu_activated (void)
2102
return _factory_menu_activated || _command_menu_activated || _property_menu_activated;
2106
ui_show_help (const String &help)
2108
if (!help.length () || !_help_dialog || !_help_scroll || !_help_area)
2111
GtkRequisition size;
2113
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (_help_scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
2115
gtk_label_set_text (GTK_LABEL (_help_area), help.c_str ());
2117
gtk_widget_size_request (_help_area, &size);
2119
if (size.width > ui_screen_width ()/2) {
2120
size.width = ui_screen_width ()/2;
2121
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (_help_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2124
if (size.height > ui_screen_height ()/2)
2125
size.height = ui_screen_height ()/2;
2127
if (size.height < size.width/2)
2128
size.height = size.width/2;
2130
gtk_widget_set_size_request (_help_scroll, size.width, size.height);
2132
gtk_window_set_position (GTK_WINDOW (_help_dialog), GTK_WIN_POS_CENTER_ALWAYS);
2133
gtk_widget_show (_help_dialog);
2136
static PangoAttrList *
2137
create_pango_attrlist (const String &mbs,
2138
const AttributeList &attrs)
2140
PangoAttrList *attrlist = pango_attr_list_new ();
2141
PangoAttribute *attr;
2143
guint start_index, end_index;
2144
guint wlen = g_utf8_strlen (mbs.c_str (), mbs.length ());
2146
for (int i=0; i < (int) attrs.size (); ++i) {
2147
start_index = attrs[i].get_start ();
2148
end_index = attrs[i].get_end ();
2150
if (end_index <= wlen && start_index < end_index) {
2151
start_index = g_utf8_offset_to_pointer (mbs.c_str (), attrs[i].get_start ()) - mbs.c_str ();
2152
end_index = g_utf8_offset_to_pointer (mbs.c_str (), attrs[i].get_end ()) - mbs.c_str ();
2154
if (attrs[i].get_type () == SCIM_ATTR_DECORATE) {
2155
if (attrs[i].get_value () == SCIM_ATTR_DECORATE_UNDERLINE) {
2156
attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
2157
attr->start_index = start_index;
2158
attr->end_index = end_index;
2159
pango_attr_list_insert (attrlist, attr);
2160
} else if (attrs[i].get_value () == SCIM_ATTR_DECORATE_REVERSE) {
2161
attr = pango_attr_foreground_new (_normal_bg.red, _normal_bg.green, _normal_bg.blue);
2162
attr->start_index = start_index;
2163
attr->end_index = end_index;
2164
pango_attr_list_insert (attrlist, attr);
2166
attr = pango_attr_background_new (_normal_text.red, _normal_text.green, _normal_text.blue);
2167
attr->start_index = start_index;
2168
attr->end_index = end_index;
2169
pango_attr_list_insert (attrlist, attr);
2170
} else if (attrs[i].get_value () == SCIM_ATTR_DECORATE_HIGHLIGHT) {
2171
attr = pango_attr_foreground_new (_active_text.red, _active_text.green, _active_text.blue);
2172
attr->start_index = start_index;
2173
attr->end_index = end_index;
2174
pango_attr_list_insert (attrlist, attr);
2176
attr = pango_attr_background_new (_active_bg.red, _active_bg.green, _active_bg.blue);
2177
attr->start_index = start_index;
2178
attr->end_index = end_index;
2179
pango_attr_list_insert (attrlist, attr);
2181
} else if (attrs[i].get_type () == SCIM_ATTR_FOREGROUND) {
2182
unsigned int color = attrs[i].get_value ();
2184
attr = pango_attr_foreground_new (SCIM_RGB_COLOR_RED(color) * 256, SCIM_RGB_COLOR_GREEN(color) * 256, SCIM_RGB_COLOR_BLUE(color) * 256);
2185
attr->start_index = start_index;
2186
attr->end_index = end_index;
2187
pango_attr_list_insert (attrlist, attr);
2188
} else if (attrs[i].get_type () == SCIM_ATTR_BACKGROUND) {
2189
unsigned int color = attrs[i].get_value ();
2191
attr = pango_attr_background_new (SCIM_RGB_COLOR_RED(color) * 256, SCIM_RGB_COLOR_GREEN(color) * 256, SCIM_RGB_COLOR_BLUE(color) * 256);
2192
attr->start_index = start_index;
2193
attr->end_index = end_index;
2194
pango_attr_list_insert (attrlist, attr);
2202
ui_command_menu_exit_activate_cb (GtkMenuItem *item,
2205
_panel_agent->exit ();
2209
ui_command_menu_reload_activate_cb (GtkMenuItem *item,
2212
_panel_agent->reload_config ();
2214
if (!_config.null ()) _config->reload ();
2218
ui_command_menu_stick_activate_cb (GtkMenuItem *item,
2221
action_toggle_window_stick ();
2225
ui_command_menu_hide_toolbar_toggled_cb (GtkMenuItem *item,
2228
_toolbar_always_hidden = ! _toolbar_always_hidden;
2230
if (_toolbar_always_hidden && !_toolbar_hidden) {
2231
gtk_widget_hide (_toolbar_window);
2232
_toolbar_hidden = true;
2233
} else if (!_toolbar_always_hidden && _panel_is_on) {
2234
gtk_widget_show (_toolbar_window);
2235
_toolbar_hidden = false;
2240
ui_command_menu_help_activate_cb (GtkMenuItem *item,
2243
if (GTK_WIDGET_VISIBLE (_help_dialog)) {
2244
gtk_widget_hide (_help_dialog);
2246
action_request_help ();
2251
ui_command_menu_helper_activate_cb (GtkWidget *item,
2254
size_t i = (size_t) GPOINTER_TO_INT (user_data);
2256
if (i < _helper_list.size ())
2257
_panel_agent->start_helper (_helper_list [i].uuid);
2261
ui_command_menu_deactivate_cb (GtkWidget *item,
2264
_command_menu_activated = false;
2265
gettimeofday (&_last_menu_deactivate_time, 0);
2268
#if ENABLE_TRAY_ICON
2270
// ui_tray_icon_destroy_cb (GtkObject *object,
2271
// gpointer user_data)
2273
// SCIM_DEBUG_MAIN (1) << "Tray Icon destroyed!\n";
2275
// gtk_widget_destroy (GTK_WIDGET (object));
2278
// _tray_icon_factory_button = 0;
2280
// g_idle_add (ui_create_tray_icon_when_idle, NULL);
2285
ui_property_activate_cb (GtkWidget *widget,
2288
GtkWidget *submenu = (GtkWidget *) g_object_get_data (G_OBJECT (widget), "property_submenu");
2291
#if GDK_MULTIHEAD_SAFE
2292
if (_current_screen)
2293
gtk_menu_set_screen (GTK_MENU (submenu), _current_screen);
2295
guint32 activate_time = gtk_get_current_event_time ();
2296
_property_menu_activated = true;
2297
gtk_menu_popup (GTK_MENU (submenu), 0, 0, 0, 0, 1, activate_time);
2301
gchar * key = (gchar *) g_object_get_data (G_OBJECT (widget), "property_key");
2304
int client = GPOINTER_TO_INT (user_data);
2307
_panel_agent->trigger_property (key);
2309
_panel_agent->trigger_helper_property (client, key);
2314
ui_property_menu_deactivate_cb (GtkWidget *item,
2317
_property_menu_activated = false;
2320
//Implementation of the action functions
2322
action_request_help (void)
2324
if (!_panel_agent->request_help ()) {
2327
help = String (_("Smart Common Input Method platform ")) +
2328
String (SCIM_VERSION) +
2329
String (_("\n(C) 2002-2005 James Su <suzhe@tsinghua.org.cn>"));
2331
ui_show_help (help);
2336
action_toggle_window_stick (void)
2340
_window_sticked = ! _window_sticked;
2342
if (_window_stick_button) {
2343
image = gtk_bin_get_child (GTK_BIN (_window_stick_button));
2344
gtk_container_remove (GTK_CONTAINER (_window_stick_button), image);
2346
image = ui_create_stick_icon (_window_sticked);
2347
gtk_container_add (GTK_CONTAINER (_window_stick_button), image);
2352
action_show_command_menu (void)
2354
if (_command_menu_activated)
2357
_command_menu_activated = true;
2359
guint32 activate_time = gtk_get_current_event_time ();
2361
if (_command_menu) {
2362
gtk_widget_destroy (_command_menu);
2366
_command_menu = gtk_menu_new ();
2368
#if GDK_MULTIHEAD_SAFE
2369
if (_current_screen)
2370
gtk_menu_set_screen (GTK_MENU (_command_menu), _current_screen);
2373
GtkWidget *menu_item;
2378
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
2380
// Add Helper object items.
2381
for (size_t i = 0; i < _helper_list.size (); ++i) {
2382
if ((_helper_list [i].option & SCIM_HELPER_STAND_ALONE) != 0 &&
2383
(_helper_list [i].option & SCIM_HELPER_AUTO_START) == 0) {
2384
menu_item = gtk_image_menu_item_new_with_label (_helper_list [i].name.c_str ());
2385
gtk_tooltips_set_tip (_tooltips, menu_item, _helper_list [i].description.c_str (), NULL);
2386
icon = ui_create_icon (_helper_list [i].icon, NULL, width, height, false);
2389
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), icon);
2391
gtk_menu_shell_append (GTK_MENU_SHELL (_command_menu), menu_item);
2393
g_signal_connect (G_OBJECT (menu_item), "activate",
2394
G_CALLBACK (ui_command_menu_helper_activate_cb),
2395
GINT_TO_POINTER ((int)i));
2397
gtk_widget_show (menu_item);
2401
if (_helper_list.size ()) {
2402
menu_item = gtk_separator_menu_item_new ();
2403
gtk_menu_shell_append (GTK_MENU_SHELL (_command_menu), menu_item);
2404
gtk_widget_show (menu_item);
2407
//Reload Configuration.
2408
menu_item = gtk_image_menu_item_new_with_label (_("Reload Configuration"));
2409
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
2410
gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_MENU));
2411
gtk_menu_shell_append (GTK_MENU_SHELL (_command_menu), menu_item);
2412
g_signal_connect (G_OBJECT (menu_item), "activate",
2413
G_CALLBACK (ui_command_menu_reload_activate_cb),
2415
gtk_widget_show_all (menu_item);
2418
menu_item = gtk_check_menu_item_new_with_label (_("Stick Windows"));
2419
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), _window_sticked);
2420
gtk_menu_shell_append (GTK_MENU_SHELL (_command_menu), menu_item);
2421
g_signal_connect (G_OBJECT (menu_item), "activate",
2422
G_CALLBACK (ui_command_menu_stick_activate_cb),
2424
gtk_widget_show_all (menu_item);
2427
menu_item = gtk_check_menu_item_new_with_label (_("Hide Toolbar"));
2428
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), _toolbar_always_hidden);
2429
gtk_menu_shell_append (GTK_MENU_SHELL (_command_menu), menu_item);
2430
g_signal_connect (G_OBJECT (menu_item), "toggled",
2431
G_CALLBACK (ui_command_menu_hide_toolbar_toggled_cb),
2433
gtk_widget_show_all (menu_item);
2436
menu_item = gtk_image_menu_item_new_with_label (_("Help ..."));
2437
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
2438
gtk_image_new_from_stock (GTK_STOCK_HELP, GTK_ICON_SIZE_MENU));
2439
gtk_menu_shell_append (GTK_MENU_SHELL (_command_menu), menu_item);
2440
g_signal_connect (G_OBJECT (menu_item), "activate",
2441
G_CALLBACK (ui_command_menu_help_activate_cb),
2443
gtk_widget_show_all (menu_item);
2445
g_signal_connect (G_OBJECT (_command_menu), "deactivate",
2446
G_CALLBACK (ui_command_menu_deactivate_cb),
2449
menu_item = gtk_separator_menu_item_new ();
2450
gtk_menu_shell_append (GTK_MENU_SHELL (_command_menu), menu_item);
2451
gtk_widget_show (menu_item);
2454
menu_item = gtk_image_menu_item_new_with_label (_("Exit"));
2455
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
2456
gtk_image_new_from_stock (GTK_STOCK_QUIT, GTK_ICON_SIZE_MENU));
2457
gtk_menu_shell_append (GTK_MENU_SHELL (_command_menu), menu_item);
2458
g_signal_connect (G_OBJECT (menu_item), "activate",
2459
G_CALLBACK (ui_command_menu_exit_activate_cb),
2461
gtk_widget_show_all (menu_item);
2463
gtk_menu_popup (GTK_MENU (_command_menu), 0, 0, 0, 0, 2, activate_time);
2466
//////////////////////////////////////////////////////////////////////
2467
// Start of PanelAgent Functions
2468
//////////////////////////////////////////////////////////////////////
2470
initialize_panel_agent (const String &config, const String &display, bool resident)
2472
_panel_agent = new PanelAgent ();
2474
if (!_panel_agent->initialize (config, display, resident))
2477
_panel_agent->signal_connect_transaction_start (slot (slot_transaction_start));
2478
_panel_agent->signal_connect_transaction_end (slot (slot_transaction_end));
2479
_panel_agent->signal_connect_reload_config (slot (slot_reload_config));
2480
_panel_agent->signal_connect_turn_on (slot (slot_turn_on));
2481
_panel_agent->signal_connect_turn_off (slot (slot_turn_off));
2482
_panel_agent->signal_connect_update_screen (slot (slot_update_screen));
2483
_panel_agent->signal_connect_update_spot_location (slot (slot_update_spot_location));
2484
_panel_agent->signal_connect_update_factory_info (slot (slot_update_factory_info));
2485
_panel_agent->signal_connect_show_help (slot (slot_show_help));
2486
_panel_agent->signal_connect_show_factory_menu (slot (slot_show_factory_menu));
2487
_panel_agent->signal_connect_show_preedit_string (slot (slot_show_preedit_string));
2488
_panel_agent->signal_connect_show_aux_string (slot (slot_show_aux_string));
2489
_panel_agent->signal_connect_show_lookup_table (slot (slot_show_lookup_table));
2490
_panel_agent->signal_connect_hide_preedit_string (slot (slot_hide_preedit_string));
2491
_panel_agent->signal_connect_hide_aux_string (slot (slot_hide_aux_string));
2492
_panel_agent->signal_connect_hide_lookup_table (slot (slot_hide_lookup_table));
2493
_panel_agent->signal_connect_update_preedit_string (slot (slot_update_preedit_string));
2494
_panel_agent->signal_connect_update_preedit_caret (slot (slot_update_preedit_caret));
2495
_panel_agent->signal_connect_update_aux_string (slot (slot_update_aux_string));
2496
_panel_agent->signal_connect_update_lookup_table (slot (slot_update_lookup_table));
2497
_panel_agent->signal_connect_register_properties (slot (slot_register_properties));
2498
_panel_agent->signal_connect_update_property (slot (slot_update_property));
2499
_panel_agent->signal_connect_register_helper_properties (slot (slot_register_helper_properties));
2500
_panel_agent->signal_connect_update_helper_property (slot (slot_update_helper_property));
2501
_panel_agent->signal_connect_register_helper (slot (slot_register_helper));
2502
_panel_agent->signal_connect_remove_helper (slot (slot_remove_helper));
2503
_panel_agent->signal_connect_lock (slot (slot_lock));
2504
_panel_agent->signal_connect_unlock (slot (slot_unlock));
2506
_panel_agent->get_helper_list (_helper_list);
2512
run_panel_agent (void)
2514
SCIM_DEBUG_MAIN(1) << "run_panel_agent ()\n";
2516
_panel_agent_thread = NULL;
2518
if (_panel_agent && _panel_agent->valid ())
2519
_panel_agent_thread = g_thread_create (panel_agent_thread_func, NULL, TRUE, NULL);
2521
return (_panel_agent_thread != NULL);
2525
panel_agent_thread_func (gpointer data)
2527
SCIM_DEBUG_MAIN(1) << "panel_agent_thread_func ()\n";
2529
if (!_panel_agent->run ())
2530
std::cerr << "Failed to run Panel.\n";
2532
G_LOCK (_global_resource_lock);
2533
_should_exit = true;
2534
G_UNLOCK (_global_resource_lock);
2536
gdk_threads_enter ();
2538
gdk_threads_leave ();
2539
g_thread_exit (NULL);
2540
return ((gpointer) NULL);
2544
start_auto_start_helpers (void)
2546
SCIM_DEBUG_MAIN(1) << "start_auto_start_helpers ()\n";
2548
// Add Helper object items.
2549
for (size_t i = 0; i < _helper_list.size (); ++i) {
2550
if ((_helper_list [i].option & SCIM_HELPER_AUTO_START) != 0) {
2551
_panel_agent->start_helper (_helper_list [i].uuid);
2557
slot_transaction_start (void)
2559
gdk_threads_enter ();
2563
slot_transaction_end (void)
2565
gdk_threads_leave ();
2569
slot_reload_config (void)
2571
if (!_config.null ()) _config->reload ();
2577
_toolbar_should_hide = false;
2578
_toolbar_hidden = false;
2579
_panel_is_on = true;
2581
gtk_widget_hide (_lookup_table_window);
2582
gtk_widget_hide (_input_window);
2583
gtk_widget_hide (_preedit_area);
2584
gtk_widget_hide (_aux_area);
2586
if (_toolbar_always_hidden)
2589
if (_frontend_properties_area)
2590
gtk_widget_hide (_frontend_properties_area);
2592
if (_window_stick_button)
2593
gtk_widget_show (_window_stick_button);
2595
if (_factory_button)
2596
gtk_widget_show (_factory_button);
2598
if (_client_properties_area)
2599
gtk_widget_show (_client_properties_area);
2602
gtk_widget_show (_menu_button);
2605
gtk_widget_show (_help_button);
2607
if (!_toolbar_always_hidden)
2608
gtk_widget_show (_toolbar_window);
2610
ui_settle_toolbar_window (true);
2614
slot_turn_off (void)
2616
if (ui_any_menu_activated ()) return;
2618
_panel_is_on = false;
2620
gtk_widget_hide (_input_window);
2621
gtk_widget_hide (_lookup_table_window);
2623
gtk_widget_hide (_preedit_area);
2624
gtk_widget_hide (_aux_area);
2626
if (_frontend_properties_area)
2627
gtk_widget_hide (_frontend_properties_area);
2629
if (_toolbar_always_show) {
2630
if (!_toolbar_hidden) {
2631
if (_window_stick_button)
2632
gtk_widget_show (_window_stick_button);
2634
if (_factory_button)
2635
gtk_widget_show (_factory_button);
2637
if (_client_properties_area)
2638
gtk_widget_show (_client_properties_area);
2641
gtk_widget_show (_menu_button);
2644
gtk_widget_show (_help_button);
2646
gtk_widget_show (_toolbar_window);
2647
ui_settle_toolbar_window (true);
2648
_toolbar_should_hide = true;
2650
gtk_widget_hide (_toolbar_window);
2651
_toolbar_hidden = true;
2656
slot_update_screen (int num)
2658
#if GDK_MULTIHEAD_SAFE
2659
if (gdk_display_get_n_screens (gdk_display_get_default ()) > num) {
2661
GdkScreen *screen = gdk_display_get_screen (gdk_display_get_default (), num);
2664
#ifdef GDK_WINDOWING_X11
2665
GdkWindow *root_window = gdk_get_default_root_window ();
2666
if (_current_screen)
2667
root_window = gdk_screen_get_root_window (_current_screen);
2668
gdk_window_remove_filter (root_window, ui_event_filter, NULL);
2671
_current_screen = screen;
2672
ui_switch_screen (screen);
2679
slot_update_factory_info (const PanelFactoryInfo &info)
2681
if (_factory_button) {
2682
GtkWidget * newlabel = 0;
2684
if (_toolbar_show_factory_icon) {
2685
newlabel = ui_create_label (info.name,
2688
!_toolbar_show_factory_name,
2691
newlabel = gtk_label_new (info.name.c_str ());
2692
if (_default_font_desc)
2693
gtk_widget_modify_font (newlabel, _default_font_desc);
2694
gtk_widget_show (newlabel);
2698
GtkWidget * old = gtk_bin_get_child (GTK_BIN (_factory_button));
2700
gtk_container_remove (GTK_CONTAINER (_factory_button), old);
2701
gtk_container_add (GTK_CONTAINER (_factory_button), newlabel);
2704
if (!GTK_WIDGET_VISIBLE (_factory_button) && !_toolbar_hidden)
2705
gtk_widget_show (_factory_button);
2708
gtk_tooltips_set_tip (_tooltips, _factory_button, info.name.c_str (), NULL);
2710
ui_settle_toolbar_window ();
2713
#if ENABLE_TRAY_ICON
2714
// if (_tray_icon_factory_button) {
2715
// GtkWidget *icon = gtk_bin_get_child (GTK_BIN (_tray_icon_factory_button));
2718
// gtk_container_remove (GTK_CONTAINER (_tray_icon_factory_button), icon);
2720
// icon = ui_create_icon (info.icon, NULL, TRAY_ICON_SIZE, TRAY_ICON_SIZE, true);
2722
// gtk_container_add (GTK_CONTAINER (_tray_icon_factory_button), icon);
2725
// gtk_tooltips_set_tip (_tooltips, _tray_icon_factory_button, info.name.c_str (), NULL);
2728
gtk_status_icon_set_from_file (_tray_icon, info.icon.c_str());
2732
if (info.uuid != "") {
2733
_recent_factory_uuids.remove(info.uuid);
2734
_recent_factory_uuids.push_front(info.uuid);
2735
if (_recent_factory_uuids.size () > 5)
2736
_recent_factory_uuids.pop_back ();
2741
slot_show_help (const String &help)
2743
ui_show_help (help);
2747
slot_show_factory_menu (const std::vector <PanelFactoryInfo> &factories)
2749
if (!_factory_menu_activated && factories.size ()) {
2752
MapStringVectorSizeT groups;
2753
std::map<String,size_t> langs, recents;
2755
guint32 activate_time = gtk_get_current_event_time ();
2757
_factory_menu_uuids.clear ();
2758
_factory_menu_activated = true;
2760
bool use_submenus = false;
2761
bool show_recent = (factories.size () > 5 && _recent_factory_uuids.size ());
2763
for (i = 0; i < factories.size (); ++i) {
2764
_factory_menu_uuids.push_back (factories [i].uuid);
2765
langs [factories [i].lang]++;
2768
std::find (_recent_factory_uuids.begin (), _recent_factory_uuids.end (),
2769
factories [i].uuid) != _recent_factory_uuids.end ()) {
2770
recents [factories [i].uuid] = i;
2772
groups [factories [i].lang].push_back (i);
2773
if (groups [factories [i].lang].size () > 1)
2774
use_submenus = true;
2778
use_submenus = (use_submenus && factories.size () > 9);
2780
if (_factory_menu) {
2781
gtk_widget_destroy (_factory_menu);
2785
_factory_menu = gtk_menu_new ();
2787
#if GDK_MULTIHEAD_SAFE
2788
if (_current_screen)
2789
gtk_menu_set_screen (GTK_MENU (_factory_menu), _current_screen);
2793
GtkWidget *menu_item;
2795
PanelFactoryInfo info;
2797
// recently used factories
2798
if (show_recent && recents.size ()) {
2799
for (std::list<String>::iterator it = _recent_factory_uuids.begin (); it != _recent_factory_uuids.end (); ++it) {
2802
info = factories [id];
2804
ui_create_factory_menu_entry (info, id, GTK_MENU_SHELL (_factory_menu), true, (langs [info.lang] > 1));
2807
MapStringVectorSizeT::iterator g = groups.find (info.lang);
2808
if (g != groups.end () && g->second.size () >= 1) {
2809
g->second.push_back (id);
2814
menu_item = gtk_separator_menu_item_new ();
2815
gtk_menu_shell_append (GTK_MENU_SHELL (_factory_menu), menu_item);
2816
gtk_widget_show (menu_item);
2819
for (MapStringVectorSizeT::iterator it = groups.begin (); it != groups.end (); ++ it) {
2820
if (use_submenus && it->second.size () > 1) {
2821
String lang = it->first;
2822
menu_item = gtk_menu_item_new_with_label (scim_get_language_name (lang).c_str ());
2823
submenu = gtk_menu_new ();
2829
for (i = 0; i < it->second.size (); ++i) {
2830
id = it->second [i];
2831
info = factories [id];
2832
ui_create_factory_menu_entry (info, id, GTK_MENU_SHELL (submenu ? submenu : _factory_menu), !submenu, (langs [info.lang] > 1));
2835
if (menu_item && submenu) {
2836
gtk_menu_shell_append (GTK_MENU_SHELL (_factory_menu), menu_item);
2837
gtk_widget_show (menu_item);
2838
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), submenu);
2839
gtk_widget_show (submenu);
2843
//Append an entry for forward mode.
2844
info = PanelFactoryInfo (String (""), String (_("English/Keyboard")), String ("C"), String (SCIM_KEYBOARD_ICON_FILE));
2845
ui_create_factory_menu_entry (info, -1, GTK_MENU_SHELL (_factory_menu), false, true);
2847
g_signal_connect (G_OBJECT (_factory_menu), "deactivate",
2848
G_CALLBACK (ui_factory_menu_deactivate_cb),
2850
gtk_menu_popup (GTK_MENU (_factory_menu), 0, 0, 0, 0, 1, activate_time);
2855
slot_update_spot_location (int x, int y)
2857
if (x > 0 && x < ui_screen_width () && y > 0 && y < ui_screen_height ()) {
2858
_spot_location_x = x;
2859
_spot_location_y = y;
2861
ui_settle_input_window ();
2862
ui_settle_lookup_table_window ();
2867
slot_show_preedit_string (void)
2869
gtk_widget_show (_preedit_area);
2871
if (_panel_is_on && !GTK_WIDGET_VISIBLE (_input_window))
2872
gtk_widget_show (_input_window);
2874
ui_settle_input_window (true, true);
2875
ui_settle_lookup_table_window ();
2879
slot_show_aux_string (void)
2881
gtk_widget_show (_aux_area);
2883
if (_panel_is_on && !GTK_WIDGET_VISIBLE (_input_window))
2884
gtk_widget_show (_input_window);
2886
ui_settle_input_window (true, true);
2887
ui_settle_lookup_table_window ();
2891
slot_show_lookup_table (void)
2893
gtk_widget_show (_lookup_table_window);
2895
if (_panel_is_on && _lookup_table_embedded && !GTK_WIDGET_VISIBLE (_input_window)) {
2896
gtk_widget_show (_input_window);
2897
ui_settle_input_window (true, true);
2900
ui_settle_lookup_table_window (true);
2904
slot_hide_preedit_string (void)
2906
gtk_widget_hide (_preedit_area);
2907
scim_string_view_set_text (SCIM_STRING_VIEW (_preedit_area), "");
2909
if (ui_can_hide_input_window ())
2910
gtk_widget_hide (_input_window);
2912
ui_settle_lookup_table_window ();
2916
slot_hide_aux_string (void)
2918
gtk_widget_hide (_aux_area);
2919
scim_string_view_set_text (SCIM_STRING_VIEW (_aux_area), "");
2921
if (ui_can_hide_input_window ())
2922
gtk_widget_hide (_input_window);
2924
ui_settle_lookup_table_window ();
2928
slot_hide_lookup_table (void)
2930
gtk_widget_hide (_lookup_table_window);
2932
if (_lookup_table_embedded && ui_can_hide_input_window ())
2933
gtk_widget_hide (_input_window);
2937
slot_update_preedit_string (const String &str, const AttributeList &attrs)
2939
PangoAttrList *attrlist = create_pango_attrlist (str, attrs);
2941
scim_string_view_set_attributes (SCIM_STRING_VIEW (_preedit_area), attrlist);
2942
scim_string_view_set_text (SCIM_STRING_VIEW (_preedit_area), str.c_str ());
2944
pango_attr_list_unref (attrlist);
2946
ui_settle_input_window (true);
2948
ui_settle_lookup_table_window ();
2952
slot_update_preedit_caret (int caret)
2954
scim_string_view_set_position (SCIM_STRING_VIEW (_preedit_area), caret);
2958
slot_update_aux_string (const String &str, const AttributeList &attrs)
2960
PangoAttrList *attrlist = create_pango_attrlist (str, attrs);
2962
scim_string_view_set_attributes (SCIM_STRING_VIEW (_aux_area), attrlist);
2963
scim_string_view_set_text (SCIM_STRING_VIEW (_aux_area), str.c_str ());
2965
pango_attr_list_unref (attrlist);
2967
ui_settle_input_window (true);
2969
ui_settle_lookup_table_window ();
2973
slot_update_lookup_table (const LookupTable &table)
2976
size_t item_num = table.get_current_page_size ();
2981
GtkRequisition size;
2982
AttributeList attrs;
2983
PangoAttrList *attrlist;
2985
if (_lookup_table_vertical) {
2986
for (i = 0; i < SCIM_LOOKUP_TABLE_MAX_PAGESIZE; ++ i) {
2990
wcs = table.get_candidate_in_current_page (i);
2992
label = table.get_candidate_label (i);
2994
if (label.length ()) {
2995
label += utf8_mbstowcs (". ");
2997
label = utf8_mbstowcs (" ");
3000
mbs = utf8_wcstombs (label+wcs);
3002
scim_string_view_set_text (SCIM_STRING_VIEW (_lookup_table_items [i]),
3005
// Update attributes;
3006
attrs = table.get_attributes_in_current_page (i);
3008
if (attrs.size ()) {
3009
for (AttributeList::iterator ait = attrs.begin (); ait != attrs.end (); ++ait)
3010
ait->set_start (ait->get_start () + label.length ());
3012
attrlist = create_pango_attrlist (mbs, attrs);
3013
scim_string_view_set_attributes (SCIM_STRING_VIEW (_lookup_table_items [i]), attrlist);
3014
pango_attr_list_unref (attrlist);
3016
scim_string_view_set_attributes (SCIM_STRING_VIEW (_lookup_table_items [i]), 0);
3019
if (i == table.get_cursor_pos_in_current_page () && table.is_cursor_visible ())
3020
scim_string_view_set_highlight (SCIM_STRING_VIEW (_lookup_table_items [i]),
3021
0, wcs.length () + 3);
3023
scim_string_view_set_highlight (SCIM_STRING_VIEW (_lookup_table_items [i]),
3026
gtk_widget_show (_lookup_table_items [i]);
3028
gtk_widget_hide (_lookup_table_items [i]);
3032
_lookup_table_index [0] = 0;
3033
for (i=0; i<SCIM_LOOKUP_TABLE_MAX_PAGESIZE; ++i) {
3035
// Update attributes
3036
AttributeList item_attrs = table.get_attributes_in_current_page (i);
3037
size_t attr_start, attr_end;
3039
label = table.get_candidate_label (i);
3041
if (label.length ()) {
3042
label += utf8_mbstowcs (".");
3047
attr_start = wcs.length ();
3049
wcs += table.get_candidate_in_current_page (i);
3051
attr_end = wcs.length ();
3053
wcs.push_back (0x20);
3055
_lookup_table_index [i+1] = wcs.length ();
3057
mbs = utf8_wcstombs (wcs);
3059
scim_string_view_set_text (SCIM_STRING_VIEW (_lookup_table_items [0]),
3062
gtk_widget_size_request (_lookup_table_window, &size);
3064
if (size.width >= ui_screen_width () / 3 && !table.is_page_size_fixed ()) {
3068
if (item_attrs.size ()) {
3069
for (AttributeList::iterator ait = item_attrs.begin (); ait != item_attrs.end (); ++ait) {
3070
ait->set_start (ait->get_start () + attr_start);
3071
if (ait->get_end () + attr_start > attr_end)
3072
ait->set_length (attr_end - ait->get_start ());
3075
attrs.insert (attrs.end (), item_attrs.begin (), item_attrs.end ());
3079
_lookup_table_index [i+1] = -1;
3083
if (attrs.size ()) {
3084
attrlist = create_pango_attrlist (mbs, attrs);
3085
scim_string_view_set_attributes (SCIM_STRING_VIEW (_lookup_table_items [0]), attrlist);
3086
pango_attr_list_unref (attrlist);
3088
scim_string_view_set_attributes (SCIM_STRING_VIEW (_lookup_table_items [0]), 0);
3091
if (table.is_cursor_visible ()) {
3092
int start = _lookup_table_index [table.get_cursor_pos_in_current_page ()];
3093
int end = _lookup_table_index [table.get_cursor_pos_in_current_page ()+1] - 1;
3094
scim_string_view_set_highlight (SCIM_STRING_VIEW (_lookup_table_items [0]), start, end);
3096
scim_string_view_set_highlight (SCIM_STRING_VIEW (_lookup_table_items [0]), -1, -1);
3100
if (table.get_current_page_start ())
3101
gtk_widget_set_sensitive (_lookup_table_up_button, TRUE);
3103
gtk_widget_set_sensitive (_lookup_table_up_button, FALSE);
3105
if (table.get_current_page_start () + item_num < table.number_of_candidates ())
3106
gtk_widget_set_sensitive (_lookup_table_down_button, TRUE);
3108
gtk_widget_set_sensitive (_lookup_table_down_button, FALSE);
3110
if (item_num < table.get_current_page_size ())
3111
_panel_agent->update_lookup_table_page_size (item_num);
3113
if (_lookup_table_embedded)
3114
ui_settle_input_window (true);
3116
ui_settle_lookup_table_window ();
3120
slot_register_properties (const PropertyList &props)
3122
register_frontend_properties (props);
3126
slot_update_property (const Property &prop)
3128
update_frontend_property (prop);
3132
slot_register_helper_properties (int id, const PropertyList &props)
3134
register_helper_properties (id, props);
3138
slot_update_helper_property (int id, const Property &prop)
3140
update_helper_property (id, prop);
3144
slot_register_helper (int id, const HelperInfo &helper)
3149
slot_remove_helper (int id)
3151
HelperPropertyRepository::iterator it = _helper_property_repository.find (id);
3153
if (it != _helper_property_repository.end () && it->second.holder)
3154
gtk_widget_destroy (it->second.holder);
3156
_helper_property_repository.erase (id);
3162
G_LOCK (_panel_agent_lock);
3168
G_UNLOCK (_panel_agent_lock);
3170
//////////////////////////////////////////////////////////////////////
3171
// End of PanelAgent-Functions
3172
//////////////////////////////////////////////////////////////////////
3175
create_properties_node (PropertyRepository &repository,
3176
PropertyList::const_iterator begin,
3177
PropertyList::const_iterator end,
3181
PropertyList::const_iterator it;
3182
PropertyList::const_iterator next;
3188
if (begin >= end) return 0;
3190
// If the level is zero, then create the this node as button, otherwise create as a menu item.
3192
GtkWidget * label = ui_create_label (begin->get_label (),
3195
!_toolbar_show_property_label,
3198
node = gtk_button_new ();
3199
gtk_container_add (GTK_CONTAINER (node), label);
3200
gtk_button_set_relief (GTK_BUTTON (node), GTK_RELIEF_NONE);
3203
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
3204
GtkWidget * icon = ui_create_icon (begin->get_icon (), NULL, width, height, false);
3205
node = gtk_image_menu_item_new_with_label (begin->get_label ().c_str ());
3207
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (node), icon);
3210
if (begin->visible ())
3211
gtk_widget_show (node);
3213
gtk_widget_hide (node);
3215
gtk_widget_set_sensitive (node, begin->active ());
3217
if (_tooltips && begin->get_tip ().length ())
3218
gtk_tooltips_set_tip (_tooltips, node, begin->get_tip ().c_str (), NULL);
3220
g_object_set_data_full (G_OBJECT (node), "property_key", g_strdup (begin->get_key ().c_str ()), g_free);
3222
info.property = *begin;
3225
repository.push_back (info);
3230
GtkWidget * submenu = gtk_menu_new ();
3232
int menu_item_idx = 0;
3234
// Create all leafs of the first child.
3236
// Find all leafs of the first child.
3237
for (next = it + 1; next != end; ++ next)
3238
if (!next->is_a_leaf_of (*it)) break;
3240
child = create_properties_node (repository, it, next, client, level + 1);
3242
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), child);
3243
g_object_set_data (G_OBJECT (child), "menu_item_idx", GINT_TO_POINTER (menu_item_idx));
3250
// The node is a button, so attach the submenu as its data.
3252
g_object_set_data_full (G_OBJECT (node), "property_submenu", submenu, (void (*)(void*)) gtk_widget_destroy);
3254
g_signal_connect (G_OBJECT (submenu), "deactivate",
3255
G_CALLBACK (ui_property_menu_deactivate_cb),
3257
} else // The node is a menu item, so attach the submenu directly.
3258
gtk_menu_item_set_submenu (GTK_MENU_ITEM (node), submenu);
3263
if (leaf || level == 0) {
3264
g_signal_connect (G_OBJECT (node),
3265
((level > 0) ? "activate" : "clicked"),
3266
G_CALLBACK (ui_property_activate_cb),
3267
GINT_TO_POINTER (client));
3274
create_properties (GtkWidget *container,
3275
PropertyRepository &repository,
3276
const PropertyList &properties,
3281
PropertyList::const_iterator it;
3282
PropertyList::const_iterator next;
3283
PropertyList::const_iterator begin = properties.begin ();
3284
PropertyList::const_iterator end = properties.end ();
3288
int menu_item_idx = 0;
3290
if (begin == end) return;
3292
root = gtk_hbox_new (FALSE, 0);
3298
if (next == end || !next->is_a_leaf_of (*it)) {
3299
GtkWidget * node = create_properties_node (repository, it, next, client, level);
3302
// The container is a hbox.
3304
gtk_box_pack_start (GTK_BOX (container), node, TRUE, TRUE, 0);
3305
// The container is a menu.
3307
gtk_menu_shell_append (GTK_MENU_SHELL (container), node);
3308
g_object_set_data (G_OBJECT (node), "menu_item_idx", GINT_TO_POINTER (menu_item_idx));
3319
register_frontend_properties (const PropertyList &properties)
3323
PropertyList::const_iterator pit = properties.begin ();
3325
if (properties.size () == 0) {
3327
} else if (properties.size () == _frontend_property_repository.size ()) {
3328
// Check if the properties are same as old ones.
3329
PropertyRepository::iterator it = _frontend_property_repository.begin ();
3331
for (; it != _frontend_property_repository.end (); ++it, ++pit) {
3332
if (it->property != *pit) {
3341
// Only update the properties.
3343
for (pit = properties.begin (); pit != properties.end (); ++pit)
3344
update_frontend_property (*pit);
3346
gtk_widget_show (_frontend_properties_area);
3347
} else { // Construct all properties.
3348
if (_frontend_properties_area)
3349
gtk_widget_destroy (_frontend_properties_area);
3351
_frontend_properties_area = 0;
3353
_frontend_property_repository.clear ();
3355
if (properties.size ()) {
3356
_frontend_properties_area = gtk_hbox_new (FALSE, 0);
3358
create_properties (_frontend_properties_area,
3359
_frontend_property_repository,
3364
gtk_widget_show (_frontend_properties_area);
3366
gtk_box_pack_start (GTK_BOX (_client_properties_area), _frontend_properties_area, TRUE,TRUE, 0);
3370
ui_settle_toolbar_window ();
3374
update_frontend_property (const Property &property)
3376
update_property (_frontend_property_repository, property);
3380
register_helper_properties (int client, const PropertyList &properties)
3382
HelperPropertyRepository::iterator it = _helper_property_repository.find (client);
3384
if (it == _helper_property_repository.end ()) {
3385
_helper_property_repository [client] = HelperPropertyInfo ();
3386
it = _helper_property_repository.find (client);
3389
if (it->second.holder)
3390
gtk_widget_destroy (it->second.holder);
3392
it->second.holder = 0;
3394
if (properties.size ()) {
3395
it->second.holder = gtk_hbox_new (FALSE, 0);
3397
create_properties (it->second.holder,
3398
it->second.repository,
3403
gtk_widget_show (it->second.holder);
3404
gtk_box_pack_end (GTK_BOX (_client_properties_area), it->second.holder, TRUE,TRUE, 0);
3407
ui_settle_toolbar_window ();
3411
update_helper_property (int client, const Property &property)
3413
update_property (_helper_property_repository [client].repository, property);
3417
update_property (PropertyRepository &repository,
3418
const Property &property)
3420
PropertyRepository::iterator it = repository.begin ();
3422
for (; it != repository.end (); ++ it) {
3423
if (it->property == property) {
3425
if (!it->widget) break;
3427
if (it->property.get_label () != property.get_label () ||
3428
it->property.get_icon () != property.get_icon ()) {
3429
if (GTK_IS_BUTTON (it->widget)) {
3430
GtkWidget *label = ui_create_label (property.get_label (),
3431
property.get_icon (),
3433
!_toolbar_show_property_label,
3435
GtkWidget *old = gtk_bin_get_child (GTK_BIN (it->widget));
3436
gtk_container_remove (GTK_CONTAINER (it->widget), old);
3437
gtk_container_add (GTK_CONTAINER (it->widget), label);
3438
} else if (GTK_IS_MENU_ITEM (it->widget)) {
3440
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
3442
GtkWidget * menu = gtk_widget_get_parent (it->widget);
3443
int menu_item_idx = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (it->widget), "menu_item_idx"));
3445
GtkWidget * icon = ui_create_icon (property.get_icon (), NULL, width, height, false);
3446
GtkWidget * new_item = gtk_image_menu_item_new_with_label (property.get_label ().c_str ());
3448
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (new_item), icon);
3450
GtkWidget * submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (it->widget));
3452
gtk_menu_item_set_submenu (GTK_MENU_ITEM (new_item), submenu);
3454
g_object_set_data_full (G_OBJECT (new_item), "property_key", g_strdup (property.get_key ().c_str ()), g_free);
3455
g_object_set_data (G_OBJECT (new_item), "menu_item_idx", GINT_TO_POINTER (menu_item_idx));
3457
gtk_widget_destroy (it->widget);
3459
it->widget = new_item;
3460
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), new_item, menu_item_idx);
3464
if (property.visible ())
3465
gtk_widget_show (it->widget);
3467
gtk_widget_hide (it->widget);
3469
gtk_widget_set_sensitive (it->widget, property.active ());
3471
if (_tooltips && property.get_tip ().length ())
3472
gtk_tooltips_set_tip (_tooltips, it->widget, property.get_tip ().c_str (), NULL);
3474
it->property = property;
3478
ui_settle_toolbar_window ();
3482
restore_properties (void)
3484
PropertyList properties;
3486
_frontend_properties_area = 0;
3488
PropertyRepository::iterator it = _frontend_property_repository.begin ();
3489
HelperPropertyRepository::iterator helper_it = _helper_property_repository.begin ();
3491
for (; it != _frontend_property_repository.end (); ++it)
3492
properties.push_back (it->property);
3494
if (properties.size ()) {
3495
_frontend_property_repository.clear ();
3496
register_frontend_properties (properties);
3499
for (; helper_it != _helper_property_repository.end (); ++ helper_it) {
3501
helper_it->second.holder = 0;
3503
properties.clear ();
3505
for (it = helper_it->second.repository.begin (); it != helper_it->second.repository.end (); ++it)
3506
properties.push_back (it->property);
3508
if (properties.size ()) {
3509
helper_it->second.repository.clear ();
3510
register_helper_properties (helper_it->first, properties);
3516
check_exit_timeout_cb (gpointer data)
3518
G_LOCK (_global_resource_lock);
3520
gdk_threads_enter ();
3522
gdk_threads_leave ();
3524
G_UNLOCK (_global_resource_lock);
3530
signalhandler(int sig)
3532
SCIM_DEBUG_MAIN (1) << "In signal handler...\n";
3533
if (_panel_agent != NULL) {
3534
_panel_agent->stop ();
3538
int main (int argc, char *argv [])
3540
std::vector<String> config_list;
3544
bool daemon = false;
3547
char **new_argv = new char * [40];
3549
String config_name ("simple");
3550
String display_name;
3551
bool should_resident = true;
3553
//Display version info
3554
std::cerr << "GTK Panel of SCIM " << SCIM_VERSION << "\n\n";
3557
scim_get_config_module_list (config_list);
3559
//Add a dummy config module, it's not really a module!
3560
config_list.push_back ("dummy");
3562
//Use socket Config module as default if available.
3563
if (config_list.size ()) {
3564
if (std::find (config_list.begin (),
3566
config_name) == config_list.end ())
3567
config_name = config_list [0];
3570
DebugOutput::disable_debug (SCIM_DEBUG_AllMask);
3571
DebugOutput::enable_debug (SCIM_DEBUG_MainMask);
3573
//parse command options
3576
if (++i >= argc) break;
3578
if (String ("-l") == argv [i] ||
3579
String ("--list") == argv [i]) {
3580
std::vector<String>::iterator it;
3583
std::cout << "Available Config module:\n";
3584
for (it = config_list.begin (); it != config_list.end (); it++)
3585
std::cout << " " << *it << "\n";
3590
if (String ("-c") == argv [i] ||
3591
String ("--config") == argv [i]) {
3593
std::cerr << "no argument for option " << argv [i-1] << "\n";
3596
config_name = argv [i];
3600
if (String ("-h") == argv [i] ||
3601
String ("--help") == argv [i]) {
3602
std::cout << "Usage: " << argv [0] << " [option]...\n\n"
3603
<< "The options are: \n"
3604
<< " --display DISPLAY Run on display DISPLAY.\n"
3605
<< " -l, --list List all of available config modules.\n"
3606
<< " -c, --config NAME Uses specified Config module.\n"
3607
<< " -d, --daemon Run " << argv [0] << " as a daemon.\n"
3608
<< " -ns, --no-stay Quit if no connected client.\n"
3610
<< " -v, --verbose LEVEL Enable debug info, to specific LEVEL.\n"
3611
<< " -o, --output FILE Output debug information into FILE.\n"
3613
<< " -h, --help Show this help message.\n";
3617
if (String ("-d") == argv [i] ||
3618
String ("--daemon") == argv [i]) {
3623
if (String ("-ns") == argv [i] ||
3624
String ("--no-stay") == argv [i]) {
3625
should_resident = false;
3629
if (String ("-v") == argv [i] ||
3630
String ("--verbose") == argv [i]) {
3632
std::cerr << "no argument for option " << argv [i-1] << "\n";
3635
DebugOutput::set_verbose_level (atoi (argv [i]));
3639
if (String ("-o") == argv [i] ||
3640
String ("--output") == argv [i]) {
3642
std::cerr << "No argument for option " << argv [i-1] << "\n";
3645
DebugOutput::set_output (argv [i]);
3649
if (String ("--display") == argv [i]) {
3651
std::cerr << "No argument for option " << argv [i-1] << "\n";
3654
display_name = argv [i];
3658
if (String ("--") == argv [i])
3661
std::cerr << "Invalid command line option: " << argv [i] << "\n";
3663
} //End of command line parsing.
3665
new_argv [new_argc ++] = argv [0];
3667
// Store the rest argvs into new_argv.
3668
for (++i; i < argc && new_argc < 40; ++i) {
3669
new_argv [new_argc ++] = argv [i];
3672
// Make up DISPLAY env.
3673
if (display_name.length ()) {
3674
new_argv [new_argc ++] = const_cast <char*> ("--display");
3675
new_argv [new_argc ++] = const_cast <char*> (display_name.c_str ());
3677
setenv ("DISPLAY", display_name.c_str (), 1);
3680
new_argv [new_argc] = 0;
3682
if (!config_name.length ()) {
3683
std::cerr << "No Config module is available!\n";
3687
if (config_name != "dummy") {
3688
//load config module
3689
_config_module = new ConfigModule (config_name);
3691
if (!_config_module || !_config_module->valid ()) {
3692
std::cerr << "Can not load " << config_name << " Config module.\n";
3696
//create config instance
3697
_config = _config_module->create_config ();
3699
_config = new DummyConfig ();
3702
if (_config.null ()) {
3703
std::cerr << "Failed to create Config instance from "
3704
<< config_name << " Config module.\n";
3709
g_thread_init (NULL);
3710
gdk_threads_init ();
3712
signal(SIGQUIT, signalhandler);
3713
signal(SIGTERM, signalhandler);
3714
signal(SIGINT, signalhandler);
3715
signal(SIGHUP, signalhandler);
3717
gtk_init (&new_argc, &new_argv);
3721
// get current display.
3723
#if GDK_MULTIHEAD_SAFE
3724
const char *p = gdk_display_get_name (gdk_display_get_default ());
3726
const char *p = getenv ("DISPLAY");
3728
if (p) display_name = String (p);
3731
if (!initialize_panel_agent (config_name, display_name, should_resident)) {
3732
std::cerr << "Failed to initialize Panel Agent!\n";
3739
// connect the configuration reload signal.
3740
_config->signal_connect_reload (slot (ui_config_reload_callback));
3742
if (!run_panel_agent()) {
3743
std::cerr << "Failed to run Socket Server!\n";
3747
start_auto_start_helpers ();
3749
// _check_exit_timeout = g_timeout_add (500, check_exit_timeout_cb, NULL);
3751
gdk_threads_enter ();
3753
gdk_threads_leave ();
3756
g_thread_join (_panel_agent_thread);
3759
std::cerr << "Successfully exited.\n";
3765
vi:ts=4:nowrap:expandtab