~ubuntu-branches/ubuntu/raring/workrave/raring

« back to all changes in this revision

Viewing changes to frontend/gtkmm/src/MainWindow.cc

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Jordi Mallach
  • Date: 2012-05-28 11:29:40 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20120528112940-bbbsjkk30fom9s8x
Tags: 1.9.909+abc941eb70-1
[ Francois Marier ]
* New upstream snapshot
  - Drop leak-fix patch (applied upstream)
  - Document how the tarball is built in README.source
* Build GNOME applets and use gsettings
* Massive update of Build-Depends as per configure.ac

* Update README.source with snapshot instructions
* Switch to machine-readable copyright file
* Update alioth git repo links
* Bump debhelper version to 9
* Bump Standards-Version to 3.9.3

[ Jordi Mallach ]
* Avoid references to GNU/Linux in manpage.
* Drop build dependency on libgnet-dev, it's obsolete and unneeded.
* Add myself to Uploaders.
* Rewrite d/rules into dh style.
  - Move all install tweaks to .install files.
  - Install manpages using dh_installman.
* As a side effect, the package installs arch-dependant data in the
  arch triplet directory; add the required Pre-Depends for m-a-support.
* Bring back GNOME Panel applet (for GNOME 3 fallback mode) and ship the
  new GNOME Shell extension (closes: #642514, #666100).
* Add private_dirs.patch: move libworkrave-private and GObject
  Introspection files to a private dir, so they are really out of the
  way, but disable it for now as it breaks the Shell extension.
* Move typelib out of the triplet dir as gobject-introspection is not
  M-A ready yet.
* Enable dh_autoreconf for the above patches.
* Add lintian overrides.
* Add necessary Breaks/Replaces as the xpm icon has moved to workrave-data.
* Prefix all debhelper files with package name.
* Suggest gnome-shell and gnome-panel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// MainWindow.cc --- Main info Window
2
2
//
3
 
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Rob Caelers & Raymond Penners
 
3
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Rob Caelers & Raymond Penners
4
4
// All rights reserved.
5
5
//
6
6
// This program is free software: you can redistribute it and/or modify
35
35
#include <unistd.h>
36
36
#endif
37
37
 
38
 
#include <iostream>
39
 
 
40
 
#include "AppletControl.hh"
 
38
#include "MainWindow.hh"
 
39
 
 
40
#include <list>
 
41
#include <gtkmm.h>
 
42
 
 
43
#include "CoreFactory.hh"
 
44
#include "IConfigurator.hh"
41
45
 
42
46
#include "TimerBoxGtkView.hh"
43
47
#include "TimerBoxControl.hh"
44
 
#include "MainWindow.hh"
45
 
#include "PreferencesDialog.hh"
46
 
#include "StatisticsDialog.hh"
47
 
#include "WindowHints.hh"
48
 
#include "TimeBar.hh"
49
48
#include "GUI.hh"
50
49
#include "Util.hh"
51
 
#include "Text.hh"
52
 
 
53
 
#include "CoreFactory.hh"
54
 
#include "IConfigurator.hh"
55
 
#include "IStatistics.hh"
56
 
 
57
 
#ifdef HAVE_DISTRIBUTION
58
 
#include "NetworkJoinDialog.hh"
59
 
#include "NetworkLogDialog.hh"
60
 
#endif
61
 
 
62
50
#include "Menus.hh"
63
51
 
64
 
#include <gtkmm/menu.h>
65
 
#include <gtkmm/stock.h>
66
 
 
67
 
#include "gtk/gtkmenu.h"
68
 
 
69
 
const string MainWindow::CFG_KEY_MAIN_WINDOW               = "gui/main_window";
70
 
const string MainWindow::CFG_KEY_MAIN_WINDOW_ALWAYS_ON_TOP = "gui/main_window/always_on_top";
71
 
const string MainWindow::CFG_KEY_MAIN_WINDOW_START_IN_TRAY = "gui/main_window/start_in_tray";
72
 
const string MainWindow::CFG_KEY_MAIN_WINDOW_X             = "gui/main_window/x";
73
 
const string MainWindow::CFG_KEY_MAIN_WINDOW_Y             = "gui/main_window/y";
74
 
const string MainWindow::CFG_KEY_MAIN_WINDOW_HEAD          = "gui/main_window/head";
75
 
 
76
52
#ifdef PLATFORM_OS_WIN32
77
53
const char *WIN32_MAIN_CLASS_NAME = "Workrave";
78
54
const UINT MYWM_TRAY_MESSAGE = WM_USER +0x100;
79
55
#endif
80
56
 
 
57
using namespace std;
81
58
 
82
59
//! Constructor.
83
60
/*!
86
63
 */
87
64
MainWindow::MainWindow() :
88
65
  enabled(true),
 
66
  can_close(true),
89
67
  timer_box_control(NULL),
90
68
  timer_box_view(NULL),
91
 
  monitor_suspended(false),
92
 
  visible(true),
93
 
  applet_active(false),
94
69
  window_location(-1, -1),
95
70
  window_head_location(-1, -1),
96
71
  window_relocated_location(-1, -1)
101
76
#ifdef PLATFORM_OS_WIN32
102
77
  show_retry_count = 0;
103
78
#endif
104
 
  init();
105
79
}
106
80
 
107
81
 
109
83
MainWindow::~MainWindow()
110
84
{
111
85
  TRACE_ENTER("MainWindow::~MainWindow");
 
86
 
 
87
  if (visible_connection.connected())
 
88
    {
 
89
      visible_connection.disconnect();
 
90
    }
 
91
 
 
92
#ifdef PLATFORM_OS_WIN32
 
93
  if (timeout_connection.connected())
 
94
    {
 
95
      timeout_connection.disconnect();
 
96
    }
 
97
#endif
 
98
 
112
99
  delete timer_box_control;
113
100
#ifdef PLATFORM_OS_WIN32
114
101
  win32_exit();
120
107
  TRACE_EXIT();
121
108
}
122
109
 
 
110
bool
 
111
MainWindow::is_visible() const
 
112
{
 
113
#if defined(PLATFORM_OS_WIN32)
 
114
  const GtkWidget *window = Gtk::Widget::gobj();
 
115
  GdkWindow *gdk_window = window->window;
 
116
  HWND hwnd = (HWND) GDK_WINDOW_HWND(gdk_window);
 
117
  return IsWindowVisible(hwnd);
 
118
#elif defined(HAVE_GTK3)
 
119
  return get_visible();
 
120
#else
 
121
  return Gtk::Window::is_visible();
 
122
#endif
 
123
}
 
124
 
 
125
 
 
126
void
 
127
MainWindow::toggle_window()
 
128
{
 
129
  TRACE_ENTER("MainWindow::toggle_window");
 
130
 
 
131
  bool visible = is_visible();
 
132
  if (visible)
 
133
    {
 
134
      close_window();
 
135
    }
 
136
  else
 
137
    {
 
138
      open_window();
 
139
    }
 
140
  TRACE_EXIT();
 
141
}
 
142
 
 
143
 
 
144
//! Opens the main window.
 
145
void
 
146
MainWindow::open_window()
 
147
{
 
148
  TRACE_ENTER("MainWindow::open_window");
 
149
  if (timer_box_view->get_visible_count() > 0)
 
150
    {
 
151
#ifdef PLATFORM_OS_WIN32
 
152
      win32_show(true);
 
153
      show_all();
 
154
#else
 
155
      show_all();
 
156
      deiconify();
 
157
#endif
 
158
 
 
159
      int x, y, head;
 
160
      set_position(Gtk::WIN_POS_NONE);
 
161
      set_gravity(Gdk::GRAVITY_STATIC);
 
162
      get_start_position(x, y, head);
 
163
 
 
164
#ifdef HAVE_GTK3
 
165
      GtkRequisition min_size;
 
166
      GtkRequisition natural_size;
 
167
      get_preferred_size(min_size, natural_size);
 
168
#else
 
169
      GtkRequisition min_size;
 
170
      on_size_request(&min_size);
 
171
#endif
 
172
 
 
173
      GUI::get_instance()->bound_head(x, y, min_size.width, min_size.height, head);
 
174
 
 
175
      GUI::get_instance()->map_from_head(x, y, head);
 
176
      TRACE_MSG("moving to " << x << " " << y);
 
177
      move(x, y);
 
178
 
 
179
      bool always_on_top = GUIConfig::get_always_on_top();
 
180
      WindowHints::set_always_on_top(this, always_on_top);
 
181
      TimerBoxControl::set_enabled("main_window", true);
 
182
    }
 
183
  TRACE_EXIT();
 
184
}
 
185
 
 
186
 
 
187
 
 
188
//! Closes the main window.
 
189
void
 
190
MainWindow::close_window()
 
191
{
 
192
  TRACE_ENTER("MainWindow::close_window");
 
193
#ifdef PLATFORM_OS_WIN32
 
194
  win32_show(false);
 
195
#elif defined(PLATFORM_OS_OSX)
 
196
  hide_all();
 
197
#else
 
198
  if (can_close)
 
199
    {
 
200
      hide();
 
201
    }
 
202
  else
 
203
    {
 
204
      iconify();
 
205
    }
 
206
#endif
 
207
 
 
208
  TimerBoxControl::set_enabled("main_window", false);
 
209
  TRACE_EXIT();
 
210
}
 
211
 
 
212
 
 
213
void
 
214
MainWindow::set_can_close(bool can_close)
 
215
{
 
216
  TRACE_ENTER_MSG("MainWindow::set_can_close", can_close);
 
217
  this->can_close = can_close;
 
218
 
 
219
  TRACE_MSG(enabled);
 
220
  if (!enabled)
 
221
    {
 
222
      if (can_close)
 
223
        { 
 
224
          TRACE_MSG("hide");
 
225
          hide();
 
226
        }
 
227
      else
 
228
        {
 
229
          TRACE_MSG("iconify");
 
230
          iconify();
 
231
          show_all();
 
232
        }
 
233
    }
 
234
  TRACE_EXIT();
 
235
}
 
236
 
 
237
 
 
238
//! Updates the main window.
 
239
void
 
240
MainWindow::update()
 
241
{
 
242
  timer_box_control->update();
 
243
}
 
244
 
 
245
 
123
246
//! Initializes the main window.
124
247
void
125
248
MainWindow::init()
131
254
 
132
255
  list<Glib::RefPtr<Gdk::Pixbuf> > icons;
133
256
 
134
 
  const char *icon_files[] = { "workrave-icon-small.png",
135
 
                               "workrave-icon-medium.png",
136
 
                               "workrave-icon-large.png" };
 
257
  const char *icon_files[] = {
 
258
    "scalable/apps/workrave.svg",
 
259
                               "16x16/apps/workrave.png",
 
260
                               "24x24/apps/workrave.png",
 
261
                               "32x32/apps/workrave.png",
 
262
                               "48x48/apps/workrave.png",
 
263
                               "64x64/apps/workrave.png",
 
264
                               "96x96/apps/workrave.png",
 
265
                               "128x128/apps/workrave.png",
 
266
                               };
137
267
 
138
268
  for (unsigned int i = 0; i < sizeof(icon_files) / sizeof(char *); i++)
139
269
    {
142
272
      try
143
273
        {
144
274
          Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create_from_file(file);
 
275
 
 
276
          TRACE_MSG(file << " size = " << pixbuf->get_width() << " " << pixbuf->get_height());
145
277
          icons.push_back(pixbuf);
146
278
        }
147
279
      catch (...)
151
283
 
152
284
  Glib::ListHandle<Glib::RefPtr<Gdk::Pixbuf> > icon_list(icons);
153
285
  Gtk::Window::set_default_icon_list(icon_list);
 
286
  //Gtk::Window::set_default_icon_name("workrave");
154
287
 
155
288
  enabled = TimerBoxControl::is_enabled("main_window");
156
289
 
246
379
  IConfigurator *config = CoreFactory::get_configurator();
247
380
  config->add_listener(TimerBoxControl::CFG_KEY_TIMERBOX + "main_window", this);
248
381
 
 
382
  visible_connection = property_visible().signal_changed().connect(sigc::mem_fun(*this, &MainWindow::on_visibility_changed));
249
383
 
250
384
  TRACE_EXIT();
251
385
}
252
386
 
253
 
 
254
 
 
255
 
 
256
387
//! Setup configuration settings.
257
388
void
258
389
MainWindow::setup()
260
391
  TRACE_ENTER("MainWindow::setup");
261
392
 
262
393
  bool new_enabled = TimerBoxControl::is_enabled("main_window");
263
 
  bool always_on_top = get_always_on_top();
 
394
  bool always_on_top = GUIConfig::get_always_on_top();
264
395
 
 
396
  TRACE_MSG("can_close " << new_enabled);
265
397
  TRACE_MSG("enabled " << new_enabled);
266
398
  TRACE_MSG("on top " << always_on_top);
267
399
 
278
410
        }
279
411
    }
280
412
 
281
 
  if (is_visible())
 
413
  bool visible = is_visible();
 
414
 
 
415
  if (visible)
282
416
    {
283
417
      WindowHints::set_always_on_top(this, always_on_top);
284
418
    }
285
 
  
286
 
  if (is_visible() && always_on_top)
 
419
 
 
420
  if (visible && always_on_top)
287
421
    {
288
422
      raise();
289
423
    }
290
 
  
291
 
  TRACE_EXIT();
292
 
}
293
 
 
294
 
 
295
 
//! Updates the main window.
296
 
void
297
 
MainWindow::update()
298
 
{
299
 
  timer_box_control->update();
300
 
}
301
 
 
302
 
 
303
 
void
304
 
MainWindow::on_activate()
305
 
{
306
 
  TRACE_ENTER("MainWindow::on_activate");
307
 
 
308
 
#ifdef PLATFORM_OS_WIN32  
309
 
  GtkWidget *window = Gtk::Widget::gobj();
310
 
  GdkWindow *gdk_window = window->window;
311
 
  HWND hwnd = (HWND) GDK_WINDOW_HWND(gdk_window);
312
 
  
313
 
  bool visible = IsWindowVisible(hwnd);
314
 
#else
315
 
  bool visible = GTK_WIDGET_VISIBLE(GTK_WIDGET(gobj()));
316
 
#endif
317
 
 
318
 
  if (visible)
319
 
    {
320
 
      close_window();
321
 
    }
322
 
  else
323
 
    {
324
 
      open_window();
325
 
    }
326
 
  TRACE_EXIT();
327
 
}
328
 
 
329
 
 
330
 
 
331
 
//! Opens the main window.
332
 
void
333
 
MainWindow::open_window()
334
 
{
335
 
  TRACE_ENTER("MainWindow::open_window");
336
 
  if (timer_box_view->get_visible_count() > 0)
337
 
    {
338
 
#ifdef PLATFORM_OS_WIN32
339
 
      win32_show(true);
340
 
      show_all();
341
 
#else
342
 
      show_all();
343
 
      deiconify();
344
 
#endif
345
 
 
346
 
      int x, y, head;
347
 
      set_position(Gtk::WIN_POS_NONE);
348
 
      set_gravity(Gdk::GRAVITY_STATIC);
349
 
      get_start_position(x, y, head);
350
 
 
351
 
      GtkRequisition req;
352
 
      on_size_request(&req);
353
 
      GUI::get_instance()->bound_head(x, y, req.width, req.height, head);
354
 
 
355
 
      GUI::get_instance()->map_from_head(x, y, head);
356
 
      TRACE_MSG("moving to " << x << " " << y);
357
 
      move(x, y);
358
 
 
359
 
      bool always_on_top = get_always_on_top();
360
 
      WindowHints::set_always_on_top(this, always_on_top);
361
 
 
362
 
      TimerBoxControl::set_enabled("main_window", true);
363
 
    }
364
 
  TRACE_EXIT();
365
 
}
366
 
 
367
 
 
368
 
 
369
 
//! Closes the main window.
370
 
void
371
 
MainWindow::close_window()
372
 
{
373
 
  TRACE_ENTER("MainWindow::close_window");
374
 
#ifdef PLATFORM_OS_WIN32
375
 
  win32_show(false);
376
 
#elif defined(PLATFORM_OS_OSX)
377
 
  hide_all();
378
 
#else
379
 
  GUI *gui = GUI::get_instance();
380
 
 
381
 
  if (applet_active || gui->is_status_icon_visible())
382
 
    {
383
 
      hide_all();
384
 
    }
385
 
  else
386
 
    {
387
 
      iconify();
388
 
    }
389
 
#endif
390
 
  GUIConfig::set_trayicon_enabled(true);
 
424
 
391
425
  TRACE_EXIT();
392
426
}
393
427
 
397
431
MainWindow::on_delete_event(GdkEventAny *)
398
432
{
399
433
  TRACE_ENTER("MainWindow::on_delete_event");
400
 
  GUI *gui = GUI::get_instance();
 
434
  IGUI *gui = GUI::get_instance();
401
435
  assert(gui != NULL);
402
436
 
403
 
#ifdef PLATFORM_OS_WIN32
 
437
#if defined(PLATFORM_OS_WIN32)
404
438
  win32_show(false);
405
 
  gui->main_window_closed();
 
439
  closed_signal.emit();
 
440
  TimerBoxControl::set_enabled("main_window", false);
 
441
#elif defined(PLATFORM_OS_OSX)
 
442
  close_window();
 
443
  TimerBoxControl::set_enabled("main_window", false);
406
444
#else
407
 
#if defined(HAVE_GNOME) || defined(HAVE_KDE)
408
 
  bool terminate = true;
409
 
  AppletControl *applet_control = gui->get_applet_control();
410
 
  if (applet_control != NULL)
 
445
  if (can_close)
411
446
    {
412
 
      terminate = ( !applet_control->is_visible() &&
413
 
                    !gui->is_status_icon_visible() );
 
447
      close_window();
 
448
      TimerBoxControl::set_enabled("main_window", false);
414
449
    }
415
 
 
416
 
  if (terminate)
 
450
  else
417
451
    {
418
452
      gui->terminate();
419
453
    }
420
 
  else
421
 
    {
422
 
      close_window();
423
 
      TimerBoxControl::set_enabled("main_window", false);
424
 
    }
425
 
#elif defined(PLATFORM_OS_OSX) 
426
 
  close_window();
427
 
  TimerBoxControl::set_enabled("main_window", false);
428
 
#else
429
 
  gui->terminate();
430
 
#endif // HAVE_GNOME || HAVE_KDE
431
 
#endif // PLATFORM_OS_WIN32
 
454
#endif
432
455
 
433
456
  TRACE_EXIT();
434
457
  return true;
435
458
}
436
459
 
437
 
 
438
 
 
439
460
//! Users pressed some mouse button in the main window.
440
461
bool
441
462
MainWindow::on_button_press_event(GdkEventButton *event)
444
465
  bool ret = false;
445
466
 
446
467
  (void) event;
447
 
  
 
468
 
448
469
#ifndef PLATFORM_OS_OSX
449
470
  // No popup menu on OS X
450
 
  
 
471
 
451
472
  if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3))
452
473
    {
453
 
      Menus::get_instance()->popup(Menus::MENU_MAINWINDOW,
454
 
                                   event->button, event->time);
 
474
      IGUI *gui = GUI::get_instance();
 
475
      Menus *menus = gui->get_menus();
 
476
      menus->popup(Menus::MENU_MAINWINDOW, event->button, event->time);
455
477
      ret = true;
456
478
    }
457
479
#endif
458
 
  
 
480
 
459
481
  TRACE_EXIT();
460
482
  return ret;
461
483
}
464
486
MainWindow::config_changed_notify(const string &key)
465
487
{
466
488
  TRACE_ENTER_MSG("MainWindow::config_changed_notify", key);
467
 
  if (key != CFG_KEY_MAIN_WINDOW_HEAD
468
 
      && key != CFG_KEY_MAIN_WINDOW_X
469
 
      && key != CFG_KEY_MAIN_WINDOW_Y)
 
489
  if (key != GUIConfig::CFG_KEY_MAIN_WINDOW_HEAD
 
490
      && key != GUIConfig::CFG_KEY_MAIN_WINDOW_X
 
491
      && key != GUIConfig::CFG_KEY_MAIN_WINDOW_Y)
470
492
    {
471
493
      setup();
472
494
    }
474
496
}
475
497
 
476
498
 
477
 
bool
478
 
MainWindow::get_always_on_top()
479
 
{
480
 
  bool rc;
481
 
  CoreFactory::get_configurator()
482
 
    ->get_value_with_default(MainWindow::CFG_KEY_MAIN_WINDOW_ALWAYS_ON_TOP,
483
 
                             rc,
484
 
                             false);
485
 
  return rc;
486
 
}
487
 
 
488
 
 
489
 
void
490
 
MainWindow::set_always_on_top(bool b)
491
 
{
492
 
  CoreFactory::get_configurator()
493
 
    ->set_value(MainWindow::CFG_KEY_MAIN_WINDOW_ALWAYS_ON_TOP, b);
494
 
}
495
 
 
496
 
 
497
 
bool
498
 
MainWindow::get_start_in_tray()
499
 
{
500
 
  bool rc;
501
 
  CoreFactory::get_configurator()
502
 
    ->get_value_with_default(CFG_KEY_MAIN_WINDOW_START_IN_TRAY, rc, false);
503
 
  return rc;
504
 
}
505
 
 
506
 
 
507
 
void
508
 
MainWindow::set_start_in_tray(bool b)
509
 
{
510
 
  CoreFactory::get_configurator()
511
 
    ->set_value(CFG_KEY_MAIN_WINDOW_START_IN_TRAY, b);
512
 
}
513
 
 
514
 
 
515
499
#ifdef PLATFORM_OS_WIN32
516
500
void
517
501
MainWindow::win32_show(bool b)
518
502
{
519
 
  TRACE_ENTER("MainWindow::win32_show");
 
503
  TRACE_ENTER_MSG("MainWindow::win32_show", b);
520
504
  bool retry = false;
521
505
 
522
506
  // Gtk's hide() seems to quit the program.
524
508
  GdkWindow *gdk_window = window->window;
525
509
  HWND hwnd = (HWND) GDK_WINDOW_HWND(gdk_window);
526
510
  ShowWindow(hwnd, b ? SW_SHOWNORMAL : SW_HIDE);
527
 
 
 
511
  visibility_changed_signal.emit();
 
512
  
528
513
        if (b)
529
514
          {
530
515
                  present();
541
526
            }
542
527
 
543
528
          TRACE_MSG("2 " << show_retry_count);
544
 
          retry = true;  
 
529
          retry = true;
545
530
        }
546
531
    }
547
532
 
549
534
    {
550
535
      if (show_retry_count > 0)
551
536
        {
552
 
          Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::win32_show_retry), 50);
 
537
          timeout_connection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::win32_show_retry), 50);
553
538
        }
554
539
    }
555
540
  else
637
622
  TRACE_ENTER("MainWindow::get_start_position");
638
623
  // FIXME: Default to right-bottom instead of 256x256
639
624
  IConfigurator *cfg = CoreFactory::get_configurator();
640
 
  cfg->get_value_with_default(CFG_KEY_MAIN_WINDOW_X, x, 256);
641
 
  cfg->get_value_with_default(CFG_KEY_MAIN_WINDOW_Y, y, 256);
642
 
  cfg->get_value_with_default(CFG_KEY_MAIN_WINDOW_HEAD, head, 0);
 
625
  cfg->get_value_with_default(GUIConfig::CFG_KEY_MAIN_WINDOW_X, x, 256);
 
626
  cfg->get_value_with_default(GUIConfig::CFG_KEY_MAIN_WINDOW_Y, y, 256);
 
627
  cfg->get_value_with_default(GUIConfig::CFG_KEY_MAIN_WINDOW_HEAD, head, 0);
643
628
  if (head < 0)
644
629
    {
645
630
      head = 0;
655
640
  TRACE_ENTER_MSG("MainWindow::set_start_position",
656
641
                  x << " " << y << " " << head);
657
642
  IConfigurator *cfg = CoreFactory::get_configurator();
658
 
  cfg->set_value(CFG_KEY_MAIN_WINDOW_X, x);
659
 
  cfg->set_value(CFG_KEY_MAIN_WINDOW_Y, y);
660
 
  cfg->set_value(CFG_KEY_MAIN_WINDOW_HEAD, head);
 
643
  cfg->set_value(GUIConfig::CFG_KEY_MAIN_WINDOW_X, x);
 
644
  cfg->set_value(GUIConfig::CFG_KEY_MAIN_WINDOW_Y, y);
 
645
  cfg->set_value(GUIConfig::CFG_KEY_MAIN_WINDOW_HEAD, head);
661
646
  TRACE_EXIT();
662
647
}
663
648
 
671
656
  int x, y, head;
672
657
  get_start_position(x, y, head);
673
658
 
674
 
  GtkRequisition req;
675
 
  on_size_request(&req);
 
659
#ifdef HAVE_GTK3
 
660
  GtkRequisition min_size;
 
661
  GtkRequisition natural_size;
 
662
  get_preferred_size(min_size, natural_size);
 
663
#else
 
664
  GtkRequisition min_size;
 
665
  on_size_request(&min_size);
 
666
#endif
676
667
 
677
 
  GUI::get_instance()->bound_head(x, y, req.width, req.height, head);
 
668
  GUI::get_instance()->bound_head(x, y, min_size.width, min_size.height, head);
678
669
 
679
670
  window_head_location.set_x(x);
680
671
  window_head_location.set_y(y);
681
672
 
682
673
  GUI::get_instance()->map_from_head(x, y, head);
683
674
 
684
 
  TRACE_MSG("Main window size " << req.width << " " << req.height);
 
675
  TRACE_MSG("Main window size " << min_size.width << " " << min_size.height);
685
676
 
686
677
  window_location.set_x(x);
687
678
  window_location.set_y(y);
692
683
  move(x, y);
693
684
}
694
685
 
695
 
 
696
 
void
697
 
MainWindow::set_applet_active(bool a)
698
 
{
699
 
  TRACE_ENTER_MSG("MainWindow::set_applet_active", a);
700
 
  applet_active = a;
701
 
 
702
 
  if (!enabled)
703
 
    {
704
 
      GUI *gui = GUI::get_instance();
705
 
      if (applet_active || gui->is_status_icon_visible())
706
 
        {
707
 
          hide_all();
708
 
        }
709
 
      else
710
 
        {
711
 
          iconify();
712
 
          show_all();
713
 
        }
714
 
    }
715
 
 
716
 
  TRACE_EXIT();
717
 
}
718
 
 
719
 
 
720
 
void
721
 
MainWindow::status_icon_changed()
722
 
{
723
 
  TRACE_ENTER("MainWindow::status_icon_changed");
724
 
  if (!enabled)
725
 
    {
726
 
      GUI *gui = GUI::get_instance();
727
 
      if (applet_active || gui->is_status_icon_visible())
728
 
        {
729
 
          hide_all();
730
 
        }
731
 
      else
732
 
        {
733
 
          iconify();
734
 
          show_all();
735
 
        }
736
 
    }
737
 
  TRACE_EXIT();
738
 
}
739
 
 
740
686
bool
741
687
MainWindow::on_configure_event(GdkEventConfigure *event)
742
688
{
763
709
      TRACE_EXIT();
764
710
      return;
765
711
    }
766
 
  
 
712
 
767
713
#ifndef PLATFORM_OS_WIN32
768
714
  // Returns bogus results on windows...sometime.
769
715
  if (event != NULL)
780
726
 
781
727
      get_position(x, y);
782
728
 
783
 
      GtkRequisition req;
784
 
      on_size_request(&req);
785
 
      width = req.width;
786
 
      height = req.height;
 
729
#ifdef HAVE_GTK3
 
730
      GtkRequisition min_size;
 
731
      GtkRequisition natural_size;
 
732
      get_preferred_size(min_size, natural_size);
 
733
#else
 
734
      GtkRequisition min_size;
 
735
      on_size_request(&min_size);
 
736
#endif
 
737
 
 
738
      width = min_size.width;
 
739
      height = min_size.height;
787
740
    }
788
741
 
789
 
 
790
742
  TRACE_MSG("main window = " << x << " " << y);
791
743
 
792
744
  if (x <= 0 && y <= 0)
847
799
      x = window_head_location.get_x();
848
800
      y = window_head_location.get_y();
849
801
 
850
 
      GUI *gui = GUI::get_instance();
 
802
      IGUI *gui = GUI::get_instance();
851
803
      int num_heads = gui->get_number_of_heads();
852
804
      for (int i = 0; i < num_heads; i++)
853
805
        {
854
806
          HeadInfo &head = gui->get_head(i);
855
807
          if (head.valid)
856
808
            {
857
 
              GtkRequisition req;
858
 
              on_size_request(&req);
859
 
              GUI::get_instance()->bound_head(x, y, req.width, req.height, i);
 
809
#ifdef HAVE_GTK3
 
810
              GtkRequisition min_size;
 
811
              GtkRequisition natural_size;
 
812
              get_preferred_size(min_size, natural_size);
 
813
#else
 
814
              GtkRequisition min_size;
 
815
              on_size_request(&min_size);
 
816
#endif
 
817
 
 
818
              GUI::get_instance()->bound_head(x, y, min_size.width, min_size.height, i);
860
819
 
861
820
              gui->map_from_head(x, y, i);
862
821
              break;
894
853
  return DefWindowProc(hwnd, uMsg, wParam, lParam);
895
854
}
896
855
#endif
 
856
 
 
857
 
 
858
void
 
859
MainWindow::on_visibility_changed()
 
860
{
 
861
  TRACE_ENTER("MainWindow::on_visibility_changed");
 
862
  TRACE_MSG(is_visible());
 
863
  visibility_changed_signal.emit();
 
864
  TRACE_EXIT();
 
865
}
 
866
 
 
867
sigc::signal<void> &
 
868
MainWindow::signal_closed()
 
869
{
 
870
  return closed_signal;
 
871
}
 
872
 
 
873
sigc::signal<void> &
 
874
MainWindow::signal_visibility_changed()
 
875
{
 
876
  return visibility_changed_signal;
 
877
}