Nux

Merge lp:~3v1n0/nux/xinputwindow-wm-pid into lp:nux

Proposed by Marco Trevisan (Treviño)
Status: Superseded
Proposed branch: lp:~3v1n0/nux/xinputwindow-wm-pid
Merge into: lp:nux
Diff against target: 228 lines (+77/-54)
2 files modified
NuxGraphics/XInputWindow.cpp (+77/-53)
NuxGraphics/XInputWindow.h (+0/-1)
To merge this branch: bzr merge lp:~3v1n0/nux/xinputwindow-wm-pid
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+169852@code.launchpad.net

Commit message

XInputWindow: define _NET_WM_PID and WM_CLIENT_MACHINE for nux windows

This makes them to be matched properly

Description of the change

Register the process pid that launched every nux input window, in this way BAMF can handle the unity windows as windows of the same application (that won't be shown anyway), instead of creating a new application for each window.
This reduces the usage of some resources both in bamf and in unity (that now will create only one hidden ApplicationLauncherIcon, instead of 5, in case of single monitor).

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NuxGraphics/XInputWindow.cpp'
2--- NuxGraphics/XInputWindow.cpp 2013-03-21 21:19:38 +0000
3+++ NuxGraphics/XInputWindow.cpp 2013-06-17 16:56:32 +0000
4@@ -24,14 +24,46 @@
5 #include "GLThread.h"
6 #include "XIMController.h"
7
8-
9-// Jay, what is this for? It isn't referenced anywhere.
10-#define xdnd_version 5
11-
12 namespace nux
13 {
14 std::vector<Window> XInputWindow::native_windows_;
15
16+ namespace atom
17+ {
18+ Atom WM_WINDOW_TYPE = 0;
19+ Atom WM_WINDOW_TYPE_DOCK = 0;
20+ Atom WM_STATE = 0;
21+ Atom WM_PID;
22+ Atom WM_CLIENT_MACHINE;
23+ Atom WM_TAKE_FOCUS = 0;
24+ Atom WM_STRUT_PARTIAL = 0;
25+ Atom X_DND_AWARE = 0;
26+ Atom OVERLAY_STRUT = 0;
27+
28+ const unsigned STRUTS_SIZE = 12;
29+ const int X_DND_VERSION = 5;
30+
31+ std::vector<Atom> WM_STATES;
32+
33+ void initialize(Display *dpy)
34+ {
35+ if (WM_WINDOW_TYPE)
36+ return;
37+
38+ WM_WINDOW_TYPE = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
39+ WM_WINDOW_TYPE_DOCK = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
40+ WM_STATE = XInternAtom(dpy, "_NET_WM_STATE", False);
41+ WM_PID = XInternAtom(dpy, "_NET_WM_PID", False);
42+ WM_CLIENT_MACHINE = XInternAtom(dpy, "WM_CLIENT_MACHINE", False);
43+ WM_TAKE_FOCUS = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
44+ X_DND_AWARE = XInternAtom(dpy, "XdndAware", False);
45+
46+ WM_STATES.push_back(XInternAtom(dpy, "_NET_WM_STATE_STICKY", False));
47+ WM_STATES.push_back(XInternAtom(dpy, "_NET_WM_STATE_SKIP_TASKBAR", False));
48+ WM_STATES.push_back(XInternAtom(dpy, "_NET_WM_STATE_SKIP_PAGER", False));
49+ }
50+ }
51+
52 XInputWindow::XInputWindow(const char* title,
53 bool take_focus,
54 int override_redirect)
55@@ -41,9 +73,9 @@
56 , geometry_(0, 0, 1, 1)
57 , shown_(false)
58 , mapped_(false)
59- , overlay_strut_atom_(0)
60 {
61 XSetWindowAttributes attrib;
62+ char hostname[256];
63
64 attrib.override_redirect = override_redirect;
65 attrib.event_mask = KeyPressMask |
66@@ -66,23 +98,24 @@
67
68 native_windows_.push_back(window_);
69
70- Atom data[32];
71- int i = 0;
72- data[i++] = XInternAtom(display_, "_NET_WM_STATE_STICKY", 0);
73- data[i++] = XInternAtom(display_, "_NET_WM_STATE_SKIP_TASKBAR", 0);
74- data[i++] = XInternAtom(display_, "_NET_WM_STATE_SKIP_PAGER", 0);
75-
76- XChangeProperty(display_, window_,
77- XInternAtom(display_, "_NET_WM_STATE", 0),
78- XA_ATOM, 32, PropModeReplace,
79- (unsigned char *) data, i);
80-
81- Atom type[1];
82- type[0] = XInternAtom(display_, "_NET_WM_WINDOW_TYPE_DOCK", 0);
83- XChangeProperty(display_, window_,
84- XInternAtom(display_, "_NET_WM_WINDOW_TYPE", 0),
85- XA_ATOM, 32, PropModeReplace,
86- (unsigned char *) type, 1);
87+ atom::initialize(display_);
88+
89+ XChangeProperty(display_, window_, atom::WM_STATE, XA_ATOM, 32, PropModeReplace,
90+ (unsigned char *) atom::WM_STATES.data(), atom::WM_STATES.size());
91+
92+ XChangeProperty(display_, window_, atom::WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace,
93+ (unsigned char *) &atom::WM_WINDOW_TYPE_DOCK, 1);
94+
95+ if (gethostname(hostname, sizeof(hostname)) > -1)
96+ {
97+ hostname[sizeof(hostname)-1] = '\0';
98+ XChangeProperty(display_, window_, atom::WM_CLIENT_MACHINE, XA_STRING, 8,
99+ PropModeReplace, (unsigned char *) hostname, strlen(hostname));
100+
101+ pid_t pid = getpid();
102+ XChangeProperty(display_, window_, atom::WM_PID, XA_CARDINAL, 32,
103+ PropModeReplace, (unsigned char *) &pid, 1);
104+ }
105
106 XStoreName(display_, window_, title);
107 EnsureInputs();
108@@ -117,7 +150,7 @@
109 XRectangle tmp_rect;
110 int largestWidth = 0, largestHeight = 0;
111 int screenWidth, screenHeight;
112- std::vector<long int> data(12, 0);
113+ std::vector<long int> data(atom::STRUTS_SIZE, 0);
114
115 /* Find the screen that this region intersects */
116 tmp_rect.x = geometry_.x;
117@@ -219,32 +252,28 @@
118
119 void XInputWindow::SetStruts()
120 {
121- std::vector<long int> data(GetStrutsData());
122+ std::vector<long int> const& struts = GetStrutsData();
123
124- XChangeProperty(display_, window_,
125- XInternAtom(display_, "_NET_WM_STRUT_PARTIAL", 0),
126- XA_CARDINAL, 32, PropModeReplace,
127- (unsigned char*) &data[0], 12);
128+ XChangeProperty(display_, window_, atom::WM_STRUT_PARTIAL, XA_CARDINAL, 32,
129+ PropModeReplace, (unsigned char*) struts.data(), struts.size());
130 }
131
132 void XInputWindow::UnsetStruts()
133 {
134- XDeleteProperty(display_, window_,
135- XInternAtom(display_, "_NET_WM_STRUT_PARTIAL", 0));
136+ XDeleteProperty(display_, window_, atom::WM_STRUT_PARTIAL);
137 }
138
139 void XInputWindow::SetOverlayStruts()
140 {
141- std::vector<long int> data(GetStrutsData());
142+ std::vector<long int> const& struts = GetStrutsData();
143
144- XChangeProperty(display_, window_, overlay_strut_atom_,
145- XA_CARDINAL, 32, PropModeReplace,
146- (unsigned char*) &data[0], 12);
147+ XChangeProperty(display_, window_, atom::OVERLAY_STRUT, XA_CARDINAL, 32,
148+ PropModeReplace, (unsigned char*) struts.data(), struts.size());
149 }
150
151 void XInputWindow::UnsetOverlayStruts()
152 {
153- XDeleteProperty(display_, window_, overlay_strut_atom_);
154+ XDeleteProperty(display_, window_, atom::OVERLAY_STRUT);
155 }
156
157 void XInputWindow::EnableStruts(bool enable)
158@@ -252,6 +281,9 @@
159 if (strutsEnabled_ == enable)
160 return;
161
162+ if (!atom::WM_STRUT_PARTIAL)
163+ atom::WM_STRUT_PARTIAL = XInternAtom(display_, "_NET_WM_STRUT_PARTIAL", False);
164+
165 strutsEnabled_ = enable;
166 if (enable)
167 SetStruts();
168@@ -269,8 +301,8 @@
169 if (overlayStrutsEnabled_ == enable)
170 return;
171
172- if (!overlay_strut_atom_)
173- overlay_strut_atom_ = XInternAtom(display_, "_COMPIZ_NET_OVERLAY_STRUT", 0);
174+ if (!atom::OVERLAY_STRUT)
175+ atom::OVERLAY_STRUT = XInternAtom(display_, "_COMPIZ_NET_OVERLAY_STRUT", False);
176
177 overlayStrutsEnabled_ = enable;
178 if (enable)
179@@ -302,30 +334,22 @@
180
181 void XInputWindow::EnableTakeFocus()
182 {
183- Atom wmTakeFocus = XInternAtom(display_, "WM_TAKE_FOCUS", False);
184- XWMHints* wmHints = NULL;
185-
186- wmHints = (XWMHints*) calloc(1, sizeof(XWMHints));
187- wmHints->flags |= InputHint;
188- wmHints->input = False;
189- XSetWMHints(display_, window_, wmHints);
190- free(wmHints);
191- XSetWMProtocols(display_, window_, &wmTakeFocus, 1);
192+ XWMHints wmHints;
193+ wmHints.flags = InputHint;
194+ wmHints.input = False;
195+ XSetWMHints(display_, window_, &wmHints);
196+ XSetWMProtocols(display_, window_, &atom::WM_TAKE_FOCUS, 1);
197 }
198
199 void XInputWindow::EnableDnd()
200 {
201- int version = 5;
202- XChangeProperty(display_, window_,
203- XInternAtom(display_, "XdndAware", false),
204- XA_ATOM, 32, PropModeReplace,
205- (unsigned char *) &version, 1);
206+ XChangeProperty(display_, window_, atom::X_DND_AWARE, XA_ATOM, 32,
207+ PropModeReplace, (unsigned char *) &atom::X_DND_VERSION, 1);
208 }
209
210 void XInputWindow::DisableDnd()
211 {
212- XDeleteProperty(display_, window_,
213- XInternAtom(display_, "XdndAware", false));
214+ XDeleteProperty(display_, window_, atom::X_DND_AWARE);
215 }
216
217 //! Set the position and size of the window
218
219=== modified file 'NuxGraphics/XInputWindow.h'
220--- NuxGraphics/XInputWindow.h 2012-08-30 22:56:57 +0000
221+++ NuxGraphics/XInputWindow.h 2013-06-17 16:56:32 +0000
222@@ -98,7 +98,6 @@
223 Rect geometry_;
224 bool shown_;
225 bool mapped_;
226- Atom overlay_strut_atom_;
227 };
228 }
229

Subscribers

People subscribed via source and target branches