/[svn]/gigedit/trunk/src/gigedit/ManagedWindow.cpp
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/ManagedWindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2893 - (show annotations) (download)
Fri Apr 29 14:19:53 2016 UTC (7 years, 11 months ago) by schoenebeck
File size: 2759 byte(s)
* Automatically save & restore window size and position
  (yet limited to main window and script editor window).
* Bumped version (1.0.0.svn6).

1 /*
2 Copyright (c) 2016 Christian Schoenebeck
3
4 This file is part of "gigedit" and released under the terms of the
5 GNU General Public License version 2.
6 */
7
8 #include "ManagedWindow.h"
9 #include <typeinfo>
10 #include <glib.h>
11 #include "global.h"
12
13 ManagedWindow::ManagedWindow() : m_listenOnConfigureEvents(false)
14 {
15 Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
16 sigc::mem_fun(*this, &ManagedWindow::restoreWindowDimensions),
17 0
18 );
19 //HACK: Gtk does not support to distinguish between user caused window resize/move and programmtical window resize/move, so as a workaround we ignore such events for a certain amount of time while this window is constructing
20 Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
21 sigc::mem_fun(*this, &ManagedWindow::enableListeningConfigureEvents),
22 300
23 );
24 }
25
26 bool ManagedWindow::on_configure_event(GdkEventConfigure* e) {
27 //printf("on_configure_event x=%d y=%d w=%d h=%d\n", e->x, e->y, e->width, e->height);
28 if (m_listenOnConfigureEvents) {
29 //printf("reset event throttle timer\n");
30 // invalidate timer (so it won't fire)
31 if (m_eventThrottleTimer) m_eventThrottleTimer->destroy();
32 // restart timer
33 m_eventThrottleTimer = Glib::TimeoutSource::create(300);
34 m_eventThrottleTimer->connect(
35 sigc::bind(
36 sigc::bind(
37 sigc::bind(
38 sigc::bind(
39 sigc::mem_fun(*this, &ManagedWindow::saveWindowDimensions),
40 e->height
41 ),
42 e->width
43 ),
44 e->y
45 ),
46 e->x
47 )
48 );
49 m_eventThrottleTimer->attach(Glib::MainContext::get_default());
50 }
51 return Gtk::Window::on_configure_event(e);
52 }
53
54 bool ManagedWindow::saveWindowDimensions(int x, int y, int w, int h) {
55 printf("saveWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h);
56 if (*windowSettingX() != x) *windowSettingX() = x;
57 if (*windowSettingY() != y) *windowSettingY() = y;
58 if (*windowSettingWidth() != w) *windowSettingWidth() = w;
59 if (*windowSettingHeight() != h) *windowSettingHeight() = h;
60 return false; // kill timeout which called this method
61 }
62
63 void ManagedWindow::restoreWindowDimensions() {
64 int x = *windowSettingX();
65 int y = *windowSettingY();
66 int w = *windowSettingWidth();
67 int h = *windowSettingHeight();
68 printf("restoreWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h);
69 if (x >= 0 && y >= 0) move(x, y);
70 if (w >= 0 && h >= 0) resize(w, h);
71 }

  ViewVC Help
Powered by ViewVC