Merge lp:~wingpanel-devs/wingpanel/wingpanel-rewrite-x11-focus into lp:~wingpanel-devs/wingpanel/trunk

Proposed by Djax
Status: Merged
Approved by: Marcus Wichelmann
Approved revision: 72
Merged at revision: 72
Proposed branch: lp:~wingpanel-devs/wingpanel/wingpanel-rewrite-x11-focus
Merge into: lp:~wingpanel-devs/wingpanel/trunk
Diff against target: 154 lines (+101/-0)
5 files modified
src/PanelWindow.vala (+5/-0)
src/Services/BackgroundManager.vala (+19/-0)
wingpanel-interface/CMakeLists.txt (+1/-0)
wingpanel-interface/DBusServer.vala (+8/-0)
wingpanel-interface/FocusManager.vala (+68/-0)
To merge this branch: bzr merge lp:~wingpanel-devs/wingpanel/wingpanel-rewrite-x11-focus
Reviewer Review Type Date Requested Status
Marcus Wichelmann (community) functionality Approve
Review via email: mp+260051@code.launchpad.net

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Marcus Wichelmann (l-admin-3) :
72. By Djax

restore last focused window after closing popover

Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

Code looks good, needs testing.

review: Approve (code style)
Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

Works, too.

review: Approve (functionality)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/PanelWindow.vala'
2--- src/PanelWindow.vala 2015-05-15 12:47:40 +0000
3+++ src/PanelWindow.vala 2015-05-25 16:19:33 +0000
4@@ -148,6 +148,11 @@
5 if (this.expanded == expanded)
6 return;
7
8+ if (expanded)
9+ Services.BackgroundManager.get_default ().remember_window ();
10+ else
11+ Services.BackgroundManager.get_default ().restore_window ();
12+
13 this.expanded = expanded;
14
15 this.set_size_request (monitor_width, expanded ? monitor_height : -1);
16
17=== modified file 'src/Services/BackgroundManager.vala'
18--- src/Services/BackgroundManager.vala 2015-05-19 21:55:19 +0000
19+++ src/Services/BackgroundManager.vala 2015-05-25 16:19:33 +0000
20@@ -28,6 +28,9 @@
21
22 public abstract BackgroundAlpha get_alpha (int screen) throws IOError;
23 public abstract async double get_background_alpha (int screen, int panel_height) throws IOError;
24+
25+ public abstract void remeber_focused_window () throws IOError;
26+ public abstract void restore_focused_window () throws IOError;
27 }
28
29 public class BackgroundManager : Object {
30@@ -64,6 +67,22 @@
31 this.screen = screen;
32 }
33
34+ public void remember_window () {
35+ try {
36+ bus.remeber_focused_window ();
37+ } catch (Error e) {
38+ warning ("Remembering focused window failed: %s", e.message);
39+ }
40+ }
41+
42+ public void restore_window () {
43+ try {
44+ bus.restore_focused_window ();
45+ } catch (Error e) {
46+ warning ("Restoring last focused window failed: %s", e.message);
47+ }
48+ }
49+
50 public void update_panel_height (int panel_height) {
51 if (this.panel_height != panel_height) {
52 this.panel_height = panel_height;
53
54=== modified file 'wingpanel-interface/CMakeLists.txt'
55--- wingpanel-interface/CMakeLists.txt 2015-05-15 12:47:40 +0000
56+++ wingpanel-interface/CMakeLists.txt 2015-05-25 16:19:33 +0000
57@@ -15,6 +15,7 @@
58 Main.vala
59 DBusServer.vala
60 AlphaManager.vala
61+ FocusManager.vala
62 Settings.vala
63 Utils.vala
64 PACKAGES
65
66=== modified file 'wingpanel-interface/DBusServer.vala'
67--- wingpanel-interface/DBusServer.vala 2015-05-19 19:07:57 +0000
68+++ wingpanel-interface/DBusServer.vala 2015-05-25 16:19:33 +0000
69@@ -27,4 +27,12 @@
70 public async double get_background_alpha (int monitor, int panel_height) {
71 return yield AlphaManager.get_default ().calculate_alpha_for_background (monitor, panel_height);
72 }
73+
74+ public void remeber_focused_window () {
75+ FocusManager.get_default ().remeber_focused_window ();
76+ }
77+
78+ public void restore_focused_window () {
79+ FocusManager.get_default ().restore_focused_window ();
80+ }
81 }
82
83=== added file 'wingpanel-interface/FocusManager.vala'
84--- wingpanel-interface/FocusManager.vala 1970-01-01 00:00:00 +0000
85+++ wingpanel-interface/FocusManager.vala 2015-05-25 16:19:33 +0000
86@@ -0,0 +1,68 @@
87+/*-
88+ * Copyright (c) 2015 Wingpanel Developers (http://launchpad.net/wingpanel)
89+ *
90+ * This program is free software: you can redistribute it and/or modify
91+ * it under the terms of the GNU Library General Public License as published by
92+ * the Free Software Foundation, either version 2.1 of the License, or
93+ * (at your option) any later version.
94+ *
95+ * This program is distributed in the hope that it will be useful,
96+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
97+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98+ * GNU Library General Public License for more details.
99+ *
100+ * You should have received a copy of the GNU Library General Public License
101+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
102+ */
103+
104+public class WingpanelInterface.FocusManager : Object {
105+ private static FocusManager? instance = null;
106+
107+ private Meta.Workspace? current_workspace = null;
108+ private Meta.Window? last_focused_window = null;
109+
110+ public FocusManager () {
111+ Main.screen.workspace_switched.connect (() => {
112+ update_current_workspace ();
113+ });
114+
115+ update_current_workspace ();
116+ }
117+
118+ public void remeber_focused_window () {
119+ var windows = current_workspace.list_windows ();
120+
121+ foreach (Meta.Window window in windows) {
122+ if (window.has_focus ()) {
123+ last_focused_window = window;
124+ return;
125+ }
126+ }
127+ }
128+
129+ public void restore_focused_window () {
130+ if (last_focused_window != null) {
131+ var display = Main.screen.get_display ();
132+ last_focused_window.focus (display.get_current_time ());
133+ }
134+ }
135+
136+ private void update_current_workspace () {
137+ var workspace = Main.screen.get_workspace_by_index (Main.screen.get_active_workspace_index ());
138+
139+ if (workspace == null) {
140+ warning ("Cannot get active workspace");
141+
142+ return;
143+ }
144+
145+ current_workspace = workspace;
146+ }
147+
148+ public static FocusManager get_default () {
149+ if (instance == null)
150+ instance = new FocusManager ();
151+
152+ return instance;
153+ }
154+}

Subscribers

People subscribed via source and target branches

to all changes: