Merge lp:~dgadomski/compiz/remember-focus into lp:compiz/0.9.12

Proposed by Dariusz Gadomski
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 3895
Merged at revision: 3891
Proposed branch: lp:~dgadomski/compiz/remember-focus
Merge into: lp:compiz/0.9.12
Diff against target: 127 lines (+60/-0)
3 files modified
metadata/core.xml.in (+5/-0)
src/privatescreen.h (+17/-0)
src/screen.cpp (+38/-0)
To merge this branch: bzr merge lp:~dgadomski/compiz/remember-focus
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+236735@code.launchpad.net

Commit message

CompScreen: Save focused window id before changing viewport.

This allows to restore focus after returning to one of the previous viewport positions.
Introduces a new setting (General Options / Focus & Raise Behaviour / Remember Focus)

Description of the change

Save focused window id before changing viewport. This allows to restore focus after returning to one of the previous viewport positions.

Introduces a new setting (General Options / Focus & Raise Behaviour / Remember Focus)

Fixes: 1125442

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Just a few inline comments...

One thing on style, make sure that you follow the compiz style, for example, adding one space between the function name and the parenthesis (such as "function ();").

Also, the indentation should be (a little annoying, I know :P):
1st level: 4 spaces, 2nd level 1 tab (set at 8 spaces), 3rd level: 1 tab + 4 spaces, 4th level: 2 tabs, and so on... :)

Revision history for this message
Dariusz Gadomski (dgadomski) wrote :

Thanks Marco, I will improve the fix.

Revision history for this message
Dariusz Gadomski (dgadomski) :
lp:~dgadomski/compiz/remember-focus updated
3891. By Dariusz Gadomski

Minor refactoring and style changes to remember-focus.

3892. By Dariusz Gadomski

Applied style fixes for PointCompare.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Looks good, just few more style fixes.

I was thinking that probably it would be better to rename the functions/members so that they mention the WS or VP (as you prefer) in their name, so that we have saveViewPortFocus() and findViewPortFocusCandidate()...

lp:~dgadomski/compiz/remember-focus updated
3893. By Dariusz Gadomski

remember_vp_focus is set to true by default.
Added 'viewport' to method names.
Corrected indentation.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) :
lp:~dgadomski/compiz/remember-focus updated
3894. By Dariusz Gadomski

Erasing saved focus even if window was not found.

3895. By Dariusz Gadomski

Simplified findViewportFocusCandidate.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Cool, looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'metadata/core.xml.in'
2--- metadata/core.xml.in 2014-04-16 12:35:24 +0000
3+++ metadata/core.xml.in 2014-10-03 10:15:44 +0000
4@@ -141,6 +141,11 @@
5 <_long>Focus prevention windows</_long>
6 <default>any</default>
7 </option>
8+ <option type="bool" name="remember_vp_focus">
9+ <_short>Remember Focus</_short>
10+ <_long>Remember Focus Per Workspace</_long>
11+ <default>true</default>
12+ </option>
13 </group>
14 <group>
15 <_short>Key bindings</_short>
16
17=== modified file 'src/privatescreen.h'
18--- src/privatescreen.h 2013-12-17 21:35:41 +0000
19+++ src/privatescreen.h 2014-10-03 10:15:44 +0000
20@@ -47,6 +47,7 @@
21
22 #include "core_options.h"
23
24+#include <map>
25 #include <set>
26
27 CompPlugin::VTable * getCoreVTable ();
28@@ -89,6 +90,17 @@
29 unsigned int viewportY;
30 };
31
32+// to allow using CompPoint as std::map keys
33+struct PointCompare
34+{
35+ bool operator () (const CompPoint& p1, const CompPoint& p2)
36+ {
37+ if (p1.x () == p2.x ())
38+ return p1.y () < p2.y ();
39+ return p1.x () < p2.x ();
40+ }
41+};
42+
43 namespace compiz
44 {
45 namespace core
46@@ -1165,6 +1177,9 @@
47
48 bool handlePingTimeout();
49
50+ void saveViewportFocus ();
51+ CompWindow * findViewportFocusCandidate ();
52+
53 Window below;
54 CompTimer autoRaiseTimer_;
55 Window autoRaiseWindow_;
56@@ -1175,6 +1190,8 @@
57 PrivateScreen privateScreen;
58 compiz::private_screen::WindowManager windowManager;
59 unsigned int showingDesktopMask_;
60+ typedef std::map<CompPoint, Window, PointCompare> FocusMap;
61+ FocusMap savedViewportFocus;
62 };
63
64 #endif
65
66=== modified file 'src/screen.cpp'
67--- src/screen.cpp 2014-06-06 09:42:08 +0000
68+++ src/screen.cpp 2014-10-03 10:15:44 +0000
69@@ -2688,6 +2688,11 @@
70 }
71 }
72 }
73+ else
74+ {
75+ // check if there was a focused window stored
76+ focus = findViewportFocusCandidate ();
77+ }
78
79 if (!focus)
80 {
81@@ -3784,6 +3789,8 @@
82 if (!tx && !ty)
83 return;
84
85+ saveViewportFocus ();
86+
87 privateScreen.viewPort.vp.setX (privateScreen.viewPort.vp.x () + tx);
88 privateScreen.viewPort.vp.setY (privateScreen.viewPort.vp.y () + ty);
89
90@@ -5155,6 +5162,37 @@
91 return true;
92 }
93
94+void
95+CompScreenImpl::saveViewportFocus ()
96+{
97+ if ((privateScreen.optionGetHsize () > 1 || privateScreen.optionGetVsize () > 1) &&
98+ privateScreen.optionGetRememberVpFocus ())
99+ {
100+ Window id = activeWindow ();
101+ if (id != None)
102+ {
103+ savedViewportFocus[privateScreen.viewPort.vp] = id;
104+ }
105+ }
106+}
107+
108+CompWindow *
109+CompScreenImpl::findViewportFocusCandidate ()
110+{
111+ if ((privateScreen.optionGetHsize () > 1 || privateScreen.optionGetVsize () > 1) &&
112+ privateScreen.optionGetRememberVpFocus ())
113+ {
114+ FocusMap::iterator it = savedViewportFocus.find (privateScreen.viewPort.vp);
115+ if (it != savedViewportFocus.end ())
116+ {
117+ Window id = it->second;
118+ savedViewportFocus.erase (it);
119+ return findWindow (id);
120+ }
121+ }
122+ return NULL;
123+}
124+
125 CompScreenImpl::~CompScreenImpl ()
126 {
127 privateScreen.startupSequence.removeAllSequences ();

Subscribers

People subscribed via source and target branches