aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/FbTk/Shape.cc43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/FbTk/Shape.cc b/src/FbTk/Shape.cc
index 3d41886..41c7885 100644
--- a/src/FbTk/Shape.cc
+++ b/src/FbTk/Shape.cc
@@ -50,6 +50,7 @@
50 50
51#include <algorithm> 51#include <algorithm>
52#include <vector> 52#include <vector>
53#include <iostream>
53 54
54using std::min; 55using std::min;
55 56
@@ -57,9 +58,7 @@ namespace FbTk {
57 58
58namespace { 59namespace {
59/* rows is an array of 8 bytes, i.e. 8x8 bits */ 60/* rows is an array of 8 bytes, i.e. 8x8 bits */
60Pixmap makePixmap(FbWindow &drawable, const unsigned char rows[]) { 61Pixmap makePixmap(Display* disp, int screen_nr, Window parent, const unsigned char rows[]) {
61
62 Display *disp = App::instance()->display();
63 62
64 const size_t data_size = 8 * 8; 63 const size_t data_size = 8 * 8;
65 // we use malloc here so we get consistent C alloc/free with XDestroyImage 64 // we use malloc here so we get consistent C alloc/free with XDestroyImage
@@ -71,7 +70,7 @@ Pixmap makePixmap(FbWindow &drawable, const unsigned char rows[]) {
71 memset(data, 0xFF, data_size); 70 memset(data, 0xFF, data_size);
72 71
73 XImage *ximage = XCreateImage(disp, 72 XImage *ximage = XCreateImage(disp,
74 DefaultVisual(disp, drawable.screenNumber()), 73 DefaultVisual(disp, screen_nr),
75 1, 74 1,
76 XYPixmap, 0, 75 XYPixmap, 0,
77 data, 76 data,
@@ -90,7 +89,7 @@ Pixmap makePixmap(FbWindow &drawable, const unsigned char rows[]) {
90 } 89 }
91 } 90 }
92 91
93 FbPixmap pm(drawable, 8, 8, 1); 92 FbPixmap pm(parent, 8, 8, 1);
94 GContext gc(pm); 93 GContext gc(pm);
95 94
96 XPutImage(disp, pm.drawable(), gc.gc(), ximage, 0, 0, 0, 0, 95 XPutImage(disp, pm.drawable(), gc.gc(), ximage, 0, 0, 0, 0,
@@ -102,10 +101,14 @@ Pixmap makePixmap(FbWindow &drawable, const unsigned char rows[]) {
102} 101}
103 102
104struct CornerPixmaps { 103struct CornerPixmaps {
104 CornerPixmaps() : do_create(true) { }
105
105 FbPixmap topleft; 106 FbPixmap topleft;
106 FbPixmap topright; 107 FbPixmap topright;
107 FbPixmap botleft; 108 FbPixmap botleft;
108 FbPixmap botright; 109 FbPixmap botright;
110
111 bool do_create;
109}; 112};
110 113
111// unfortunately, we need a separate pixmap per screen 114// unfortunately, we need a separate pixmap per screen
@@ -113,21 +116,33 @@ std::vector<CornerPixmaps> s_corners;
113 116
114unsigned long nr_shapes = 0; 117unsigned long nr_shapes = 0;
115 118
116void initCorners(FbWindow& win) { 119void initCorners(int screen) {
117 120
121 Display* disp = App::instance()->display();
118 if (s_corners.empty()) 122 if (s_corners.empty())
119 s_corners.resize(ScreenCount(App::instance()->display())); 123 s_corners.resize(ScreenCount(disp));
124
125
126 if (screen < 0 || screen > static_cast<int>(s_corners.size())) {
127 std::cerr << "FbTk/Shape.cc:initCorners(), invalid argument: " << screen << "\n";
128 return;
129 }
120 130
121 static const unsigned char left_bits[] = { 0xc0, 0xf8, 0xfc, 0xfe, 0xfe, 0xfe, 0xff, 0xff }; 131 static const unsigned char left_bits[] = { 0xc0, 0xf8, 0xfc, 0xfe, 0xfe, 0xfe, 0xff, 0xff };
122 static const unsigned char right_bits[] = { 0x03, 0x1f, 0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff}; 132 static const unsigned char right_bits[] = { 0x03, 0x1f, 0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff};
123 static const unsigned char bottom_left_bits[] = { 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfc, 0xf8, 0xc0 }; 133 static const unsigned char bottom_left_bits[] = { 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfc, 0xf8, 0xc0 };
124 static const unsigned char bottom_right_bits[] = { 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x3f, 0x1f, 0x03 }; 134 static const unsigned char bottom_right_bits[] = { 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x3f, 0x1f, 0x03 };
125 135
126 const int screen_num = win.screenNumber(); 136 CornerPixmaps& corners = s_corners[screen];
127 s_corners[screen_num].topleft = makePixmap(win, left_bits); 137 if (corners.do_create) {
128 s_corners[screen_num].topright = makePixmap(win, right_bits); 138
129 s_corners[screen_num].botleft = makePixmap(win, bottom_left_bits); 139 Window root = RootWindow(disp, screen);
130 s_corners[screen_num].botright = makePixmap(win, bottom_right_bits); 140 corners.topleft = makePixmap(disp, screen, root, left_bits);
141 corners.topright = makePixmap(disp, screen, root, right_bits);
142 corners.botleft = makePixmap(disp, screen, root, bottom_left_bits);
143 corners.botright = makePixmap(disp, screen, root, bottom_right_bits);
144 corners.do_create = false;
145 }
131 146
132 nr_shapes++; // refcounting 147 nr_shapes++; // refcounting
133} 148}
@@ -151,7 +166,7 @@ Shape::Shape(FbWindow &win, int shapeplaces):
151 m_shapeplaces(shapeplaces) { 166 m_shapeplaces(shapeplaces) {
152 167
153#ifdef SHAPE 168#ifdef SHAPE
154 initCorners(win); 169 initCorners(win.screenNumber());
155#endif 170#endif
156 171
157 update(); 172 update();
@@ -287,7 +302,7 @@ void Shape::update() {
287 XDestroyRegion(clip); 302 XDestroyRegion(clip);
288 XDestroyRegion(bound); 303 XDestroyRegion(bound);
289 304
290 CornerPixmaps &corners = s_corners[m_win->screenNumber()]; 305 const CornerPixmaps &corners = s_corners[m_win->screenNumber()];
291#define SHAPECORNER(corner, x, y, shapekind) \ 306#define SHAPECORNER(corner, x, y, shapekind) \
292 XShapeCombineMask(App::instance()->display(), \ 307 XShapeCombineMask(App::instance()->display(), \
293 m_win->window(), \ 308 m_win->window(), \