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

Proposed by Dariusz Gadomski
Status: Work in progress
Proposed branch: lp:~dgadomski/compiz/remember-focus-0.9.11
Merge into: lp:compiz/0.9.11
Diff against target: 119 lines (+59/-0)
3 files modified
metadata/core.xml.in (+5/-0)
src/privatescreen.h (+16/-0)
src/screen.cpp (+38/-0)
To merge this branch: bzr merge lp:~dgadomski/compiz/remember-focus-0.9.11
Reviewer Review Type Date Requested Status
Christopher Townsend Needs Fixing
Marco Trevisan (Treviño) Approve
Review via email: mp+237622@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

Backport of the feature to the 0.9.11 series.

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

This code introduces regressions as seen in bug #1393020 and bug #1398512. We have to revert this change in lp:compiz because of this, so I'm going to move this MP to work in progress pending a proper fix.

Thanks!

review: Needs Fixing

Unmerged revisions

3867. By Dariusz Gadomski

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)

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-08 15:59:00 +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-08 15:59:00 +0000
20@@ -89,6 +89,17 @@
21 unsigned int viewportY;
22 };
23
24+// to allow using CompPoint as std::map keys
25+struct PointCompare
26+{
27+ bool operator () (const CompPoint& p1, const CompPoint& p2)
28+ {
29+ if (p1.x () == p2.x ())
30+ return p1.y () < p2.y ();
31+ return p1.x () < p2.x ();
32+ }
33+};
34+
35 namespace compiz
36 {
37 namespace core
38@@ -1165,6 +1176,9 @@
39
40 bool handlePingTimeout();
41
42+ void saveViewportFocus ();
43+ CompWindow * findViewportFocusCandidate ();
44+
45 Window below;
46 CompTimer autoRaiseTimer_;
47 Window autoRaiseWindow_;
48@@ -1175,6 +1189,8 @@
49 PrivateScreen privateScreen;
50 compiz::private_screen::WindowManager windowManager;
51 unsigned int showingDesktopMask_;
52+ typedef std::map<CompPoint, Window, PointCompare> FocusMap;
53+ FocusMap savedViewportFocus;
54 };
55
56 #endif
57
58=== modified file 'src/screen.cpp'
59--- src/screen.cpp 2014-06-11 14:44:06 +0000
60+++ src/screen.cpp 2014-10-08 15:59:00 +0000
61@@ -2688,6 +2688,11 @@
62 }
63 }
64 }
65+ else
66+ {
67+ // check if there was a focused window stored
68+ focus = findViewportFocusCandidate ();
69+ }
70
71 if (!focus)
72 {
73@@ -3784,6 +3789,8 @@
74 if (!tx && !ty)
75 return;
76
77+ saveViewportFocus ();
78+
79 privateScreen.viewPort.vp.setX (privateScreen.viewPort.vp.x () + tx);
80 privateScreen.viewPort.vp.setY (privateScreen.viewPort.vp.y () + ty);
81
82@@ -5155,6 +5162,37 @@
83 return true;
84 }
85
86+void
87+CompScreenImpl::saveViewportFocus ()
88+{
89+ if ((privateScreen.optionGetHsize () > 1 || privateScreen.optionGetVsize () > 1) &&
90+ privateScreen.optionGetRememberVpFocus ())
91+ {
92+ Window id = activeWindow ();
93+ if (id != None)
94+ {
95+ savedViewportFocus[privateScreen.viewPort.vp] = id;
96+ }
97+ }
98+}
99+
100+CompWindow *
101+CompScreenImpl::findViewportFocusCandidate ()
102+{
103+ if ((privateScreen.optionGetHsize () > 1 || privateScreen.optionGetVsize () > 1) &&
104+ privateScreen.optionGetRememberVpFocus ())
105+ {
106+ FocusMap::iterator it = savedViewportFocus.find (privateScreen.viewPort.vp);
107+ if (it != savedViewportFocus.end ())
108+ {
109+ Window id = it->second;
110+ savedViewportFocus.erase (it);
111+ return findWindow (id);
112+ }
113+ }
114+ return NULL;
115+}
116+
117 CompScreenImpl::~CompScreenImpl ()
118 {
119 privateScreen.startupSequence.removeAllSequences ();

Subscribers

People subscribed via source and target branches