Nux

Merge lp:~3v1n0/nux/xinputwindow-cache-atoms into lp:nux

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 800
Merged at revision: 796
Proposed branch: lp:~3v1n0/nux/xinputwindow-cache-atoms
Merge into: lp:nux
Prerequisite: lp:~3v1n0/nux/autoreconf-doxygen-fix
Diff against target: 210 lines (+61/-54)
2 files modified
NuxGraphics/XInputWindow.cpp (+61/-53)
NuxGraphics/XInputWindow.h (+0/-1)
To merge this branch: bzr merge lp:~3v1n0/nux/xinputwindow-cache-atoms
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Andrea Azzarone (community) Approve
Review via email: mp+169838@code.launchpad.net

Commit message

XinputWindow: cache the X Atoms we use for all the nux windows

This reduces the time to create a window, as we call XInternAtom just once

Description of the change

For each atom we use in Nux XInputWindow we always call the slow XInternAtom, while we can safely cache these values for all the windows we create reducing the initialization time.

To post a comment you must log in.
800. By Marco Trevisan (Treviño)

XInputWindow: cache missing WM_STRUT_PARTIAL, some code cleanup

Revision history for this message
Andrea Azzarone (azzar1) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

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

Subscribers

People subscribed via source and target branches