/[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 2918 - (show annotations) (download)
Wed May 18 10:10:25 2016 UTC (7 years, 11 months ago) by schoenebeck
File size: 6258 byte(s)
* Added setting to main menu "View" -> "Auto Restore Window Dimension"
  (disabled by default since it causes issues on some machines).
* Bumped version (1.0.0.svn14).

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 ///////////////////////////////////////////////////////////////////////////
14 // class 'ManagedWindow'
15
16 ManagedWindow::ManagedWindow() : m_listenOnConfigureEvents(false)
17 {
18 if (!Settings::singleton()->autoRestoreWindowDimension)
19 return;
20
21 Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
22 sigc::mem_fun(*this, &ManagedWindow::restoreWindowDimensions),
23 0
24 );
25 //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
26 Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
27 sigc::mem_fun(*this, &ManagedWindow::enableListeningConfigureEvents),
28 300
29 );
30 }
31
32 bool ManagedWindow::on_configure_event(GdkEventConfigure* e) {
33 //printf("on_configure_event x=%d y=%d w=%d h=%d\n", e->x, e->y, e->width, e->height);
34 if (m_listenOnConfigureEvents) {
35 //printf("reset event throttle timer\n");
36 // invalidate timer (so it won't fire)
37 if (m_eventThrottleTimer) m_eventThrottleTimer->destroy();
38 // restart timer
39 m_eventThrottleTimer = Glib::TimeoutSource::create(300);
40 m_eventThrottleTimer->connect(
41 sigc::bind(
42 sigc::bind(
43 sigc::bind(
44 sigc::bind(
45 sigc::mem_fun(*this, &ManagedWindow::saveWindowDimensions),
46 e->height
47 ),
48 e->width
49 ),
50 e->y
51 ),
52 e->x
53 )
54 );
55 m_eventThrottleTimer->attach(Glib::MainContext::get_default());
56 }
57 return Gtk::Window::on_configure_event(e);
58 }
59
60 bool ManagedWindow::saveWindowDimensions(int x, int y, int w, int h) {
61 printf("saveWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h);
62 if (*windowSettingX() != x) *windowSettingX() = x;
63 if (*windowSettingY() != y) *windowSettingY() = y;
64 if (*windowSettingWidth() != w) *windowSettingWidth() = w;
65 if (*windowSettingHeight() != h) *windowSettingHeight() = h;
66 return false; // kill timeout which called this method
67 }
68
69 void ManagedWindow::restoreWindowDimensions() {
70 int x = *windowSettingX();
71 int y = *windowSettingY();
72 int w = *windowSettingWidth();
73 int h = *windowSettingHeight();
74 printf("restoreWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h);
75 if (x >= 0 && y >= 0) move(x, y);
76 if (w > 0 && h > 0) resize(w, h);
77 }
78
79 ///////////////////////////////////////////////////////////////////////////
80 // class 'ManagedDialog'
81
82 ManagedDialog::ManagedDialog()
83 : Gtk::Dialog(), m_listenOnConfigureEvents(false)
84 {
85 initManagedDialog();
86 }
87
88 ManagedDialog::ManagedDialog(const Glib::ustring& title, bool modal)
89 : Gtk::Dialog(title, modal), m_listenOnConfigureEvents(false)
90 {
91 initManagedDialog();
92 }
93
94 ManagedDialog::ManagedDialog(const Glib::ustring& title, Gtk::Window& parent, bool modal)
95 : Gtk::Dialog(title, parent, modal), m_listenOnConfigureEvents(false)
96 {
97 initManagedDialog();
98 }
99
100 // ManagedDialog::ManagedDialog(const Glib::ustring& title, Gtk::DialogFlags flags)
101 // : Gtk::Dialog(title, flags), m_listenOnConfigureEvents(false)
102 // {
103 // initManagedDialog();
104 // }
105
106 void ManagedDialog::initManagedDialog() {
107 if (!Settings::singleton()->autoRestoreWindowDimension)
108 return;
109
110 Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
111 sigc::mem_fun(*this, &ManagedDialog::restoreWindowDimensions),
112 0
113 );
114 //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
115 Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
116 sigc::mem_fun(*this, &ManagedDialog::enableListeningConfigureEvents),
117 300
118 );
119 }
120
121 bool ManagedDialog::on_configure_event(GdkEventConfigure* e) {
122 //printf("on_configure_event x=%d y=%d w=%d h=%d\n", e->x, e->y, e->width, e->height);
123 if (m_listenOnConfigureEvents) {
124 //printf("reset event throttle timer\n");
125 // invalidate timer (so it won't fire)
126 if (m_eventThrottleTimer) m_eventThrottleTimer->destroy();
127 // restart timer
128 m_eventThrottleTimer = Glib::TimeoutSource::create(300);
129 m_eventThrottleTimer->connect(
130 sigc::bind(
131 sigc::bind(
132 sigc::bind(
133 sigc::bind(
134 sigc::mem_fun(*this, &ManagedDialog::saveWindowDimensions),
135 e->height
136 ),
137 e->width
138 ),
139 e->y
140 ),
141 e->x
142 )
143 );
144 m_eventThrottleTimer->attach(Glib::MainContext::get_default());
145 }
146 return Gtk::Dialog::on_configure_event(e);
147 }
148
149 bool ManagedDialog::saveWindowDimensions(int x, int y, int w, int h) {
150 printf("saveDialogDimensions(%d,%d,%d,%d)\n",x,y,w,h);
151 if (*windowSettingX() != x) *windowSettingX() = x;
152 if (*windowSettingY() != y) *windowSettingY() = y;
153 if (*windowSettingWidth() != w) *windowSettingWidth() = w;
154 if (*windowSettingHeight() != h) *windowSettingHeight() = h;
155 return false; // kill timeout which called this method
156 }
157
158 void ManagedDialog::restoreWindowDimensions() {
159 int x = *windowSettingX();
160 int y = *windowSettingY();
161 int w = *windowSettingWidth();
162 int h = *windowSettingHeight();
163 printf("restoreDialogDimensions(%d,%d,%d,%d)\n",x,y,w,h);
164 if (x >= 0 && y >= 0) move(x, y);
165 if (w > 0 && h >= 0) resize(w, h);
166 }

  ViewVC Help
Powered by ViewVC