Merge lp:~christriant/switchboard/fix-1101263 into lp:~elementary-pantheon/switchboard/switchboard

Proposed by Chris Triantafillis
Status: Merged
Approved by: Cody Garver
Approved revision: 421
Merged at revision: 419
Proposed branch: lp:~christriant/switchboard/fix-1101263
Merge into: lp:~elementary-pantheon/switchboard/switchboard
Diff against target: 158 lines (+88/-2)
4 files modified
CMakeLists.txt (+4/-0)
schemas/CMakeLists.txt (+2/-0)
schemas/org.pantheon.switchboard.gschema.xml (+29/-0)
src/Switchboard.vala (+53/-2)
To merge this branch: bzr merge lp:~christriant/switchboard/fix-1101263
Reviewer Review Type Date Requested Status
elementary Pantheon team Pending
Review via email: mp+210924@code.launchpad.net

Commit message

Remember window size to fix bug #1101263

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

Hmm, please remember to never hardcode destination strings, string like "/usr/share/glib-2.0/schemas/" should never exists on CMake.
Please refer to CMakeLists.txt from other projects where it is done properly.
I'll correct this in trunk.

Revision history for this message
Chris Triantafillis (christriant) wrote :

Thanks! I'm not very good with cmake :)

Revision history for this message
Corentin Noël (tintou) wrote :

This branch introduced a bug, fixed in trunk, for your information here is why:
when connecting for the window_state_event (Switchboard.vala, line 175) you did return true to the connect function. As specified in the documentation, returning true does not send the signal to other connect function, that's why the window was not good maximizing, to fix this, you need to return false.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-02-23 19:51:27 +0000
3+++ CMakeLists.txt 2014-03-13 22:31:56 +0000
4@@ -7,6 +7,7 @@
5
6 include (GNUInstallDirs)
7 set (DATADIR ${CMAKE_INSTALL_FULL_DATAROOTDIR})
8+set (GSETTINGSDIR "/usr/share/glib-2.0/schemas/")
9 set (PKGDATADIR "${DATADIR}/${CMAKE_PROJECT_NAME}")
10 set (GETTEXT_PACKAGE "${CMAKE_PROJECT_NAME}")
11 set (RELEASE_NAME "Preferences with piazzaz.")
12@@ -137,3 +138,6 @@
13 if (BUILD_SAMPLE)
14 add_subdirectory (sample)
15 endif ()
16+
17+add_subdirectory (schemas)
18+install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/schemas/org.pantheon.switchboard.gschema.xml DESTINATION ${GSETTINGSDIR})
19\ No newline at end of file
20
21=== added directory 'schemas'
22=== added file 'schemas/CMakeLists.txt'
23--- schemas/CMakeLists.txt 1970-01-01 00:00:00 +0000
24+++ schemas/CMakeLists.txt 2014-03-13 22:31:56 +0000
25@@ -0,0 +1,2 @@
26+include(GSettings)
27+add_schema("org.pantheon.switchboard.gschema.xml")
28\ No newline at end of file
29
30=== added file 'schemas/org.pantheon.switchboard.gschema.xml'
31--- schemas/org.pantheon.switchboard.gschema.xml 1970-01-01 00:00:00 +0000
32+++ schemas/org.pantheon.switchboard.gschema.xml 2014-03-13 22:31:56 +0000
33@@ -0,0 +1,29 @@
34+<?xml version="1.0" encoding="UTF-8"?>
35+<schemalist>
36+ <enum id="switchboard-window-states">
37+ <value nick="Normal" value="0" />
38+ <value nick="Maximized" value="1" />
39+ </enum>
40+ <schema path="/org/pantheon/switchboard/saved-state/" id="org.pantheon.switchboard.saved-state" gettext-domain="switchboard">
41+ <key name="window-state" enum="switchboard-window-states">
42+ <default>"Normal"</default>
43+ <summary>The saved state of the window.</summary>
44+ <description>The saved state of the window.</description>
45+ </key>
46+ <key name="window-width" type="i">
47+ <default>842</default>
48+ <summary>The saved width of the window.</summary>
49+ <description>The saved width of the window. Must be greater than 700, or it will not take effect.</description>
50+ </key>
51+ <key name="window-height" type="i">
52+ <default>475</default>
53+ <summary>The saved height of the window.</summary>
54+ <description>The saved height of the window. Must be greater than 400, or it will not take effect.</description>
55+ </key>
56+ <key name="position" type="as">
57+ <default>['']</default>
58+ <summary>The position of the window.</summary>
59+ <description>The position of the window.</description>
60+ </key>
61+ </schema>
62+</schemalist>
63
64=== modified file 'src/Switchboard.vala'
65--- src/Switchboard.vala 2014-01-31 18:21:51 +0000
66+++ src/Switchboard.vala 2014-03-13 22:31:56 +0000
67@@ -22,6 +22,11 @@
68 { null }
69 };
70
71+ public enum WindowState {
72+ NORMAL = 0,
73+ MAXIMIZED = 1
74+ }
75+
76 private static string? plug_to_open = null;
77
78 public static int main (string[] args) {
79@@ -55,6 +60,10 @@
80 public Switchboard.Plug current_plug;
81 public Gtk.SearchEntry search_box { public get; private set; }
82
83+ private GLib.Settings settings;
84+ private int default_width = 0;
85+ private int default_height = 0;
86+
87 construct {
88 application_id = "org.elementary.Switchboard";
89 program_name = "Switchboard";
90@@ -87,6 +96,7 @@
91
92 loaded_plugs = new Gee.LinkedList <string> ();
93 Switchboard.PlugsManager.get_default ();
94+ settings = new GLib.Settings ("org.pantheon.switchboard.saved-state");
95 build ();
96 category_view.load_default_plugs ();
97 if (current_plug != null)
98@@ -154,10 +164,22 @@
99 main_window.icon_name = app_icon;
100
101 // Set up window
102- main_window.set_default_size (842, 475);
103+ restore_saved_state ();
104+ main_window.set_default_size (default_width, default_height);
105 main_window.set_size_request (500, 300);
106- main_window.window_position = Gtk.WindowPosition.CENTER;
107 main_window.destroy.connect (shut_down);
108+ main_window.delete_event.connect (() => {
109+ update_saved_state ();
110+ return false;
111+ });
112+ main_window.window_state_event.connect ((event) => {
113+ if (event.new_window_state == Gdk.WindowState.MAXIMIZED)
114+ settings.set_enum ("window-state", WindowState.MAXIMIZED);
115+ else
116+ settings.set_enum ("window-state", WindowState.NORMAL);
117+
118+ return true;
119+ });
120 setup_toolbar ();
121
122 // Set up accelerators (hotkeys)
123@@ -216,6 +238,35 @@
124 Gtk.main_quit ();
125 }
126
127+ private void restore_saved_state () {
128+ // Restore window's state
129+ default_width = settings.get_int ("window-width");
130+ default_height = settings.get_int ("window-height");
131+ var position = settings.get_strv ("position");
132+
133+ if (settings.get_enum ("window-state") == WindowState.MAXIMIZED) {
134+ main_window.maximize ();
135+ } else {
136+ if (position.length != 2)
137+ main_window.window_position = Gtk.WindowPosition.CENTER;
138+ else
139+ main_window.move (int.parse (position[0]), int.parse (position[1]));
140+ }
141+ }
142+
143+ private void update_saved_state () {
144+ // Update saved state of window
145+ if (settings.get_enum ("window-state") == WindowState.NORMAL) {
146+ int width, height, x, y;
147+ main_window.get_size (out width, out height);
148+ main_window.get_position (out x, out y);
149+ settings.set_int ("window-width", width);
150+ settings.set_int ("window-height", height);
151+ string[] position = {x.to_string (), y.to_string ()};
152+ settings.set_strv ("position", position);
153+ }
154+ }
155+
156 // Change Switchboard title back to "Switchboard"
157 private void reset_title () {
158 headerbar.subtitle = null;

Subscribers

People subscribed via source and target branches