Changeset View
Changeset View
Standalone View
Standalone View
utils.cpp
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | |||||
89 | { | 89 | { | ||
90 | assert(server_grab_count > 0); | 90 | assert(server_grab_count > 0); | ||
91 | if (--server_grab_count == 0) { | 91 | if (--server_grab_count == 0) { | ||
92 | xcb_ungrab_server(connection()); | 92 | xcb_ungrab_server(connection()); | ||
93 | xcb_flush(connection()); | 93 | xcb_flush(connection()); | ||
94 | } | 94 | } | ||
95 | } | 95 | } | ||
96 | 96 | | |||
97 | bool grabbedXServer() | | |||
98 | { | | |||
99 | return server_grab_count > 0; | | |||
100 | } | | |||
101 | | ||||
102 | static bool keyboard_grabbed = false; | 97 | static bool keyboard_grabbed = false; | ||
103 | 98 | | |||
104 | bool grabXKeyboard(xcb_window_t w) | 99 | bool grabXKeyboard(xcb_window_t w) | ||
105 | { | 100 | { | ||
106 | if (QWidget::keyboardGrabber() != NULL) | 101 | if (QWidget::keyboardGrabber() != NULL) | ||
107 | return false; | 102 | return false; | ||
108 | if (keyboard_grabbed) | 103 | if (keyboard_grabbed) | ||
109 | return false; | 104 | return false; | ||
Show All 39 Lines | 140 | { | |||
149 | sigaddset(&userSiganls, SIGUSR2); | 144 | sigaddset(&userSiganls, SIGUSR2); | ||
150 | pthread_sigmask(SIG_UNBLOCK, &userSiganls, nullptr); | 145 | pthread_sigmask(SIG_UNBLOCK, &userSiganls, nullptr); | ||
151 | } | 146 | } | ||
152 | 147 | | |||
153 | #endif | 148 | #endif | ||
154 | 149 | | |||
155 | // converting between X11 mouse/keyboard state mask and Qt button/keyboard states | 150 | // converting between X11 mouse/keyboard state mask and Qt button/keyboard states | ||
156 | 151 | | |||
157 | int qtToX11Button(Qt::MouseButton button) | | |||
158 | { | | |||
159 | if (button == Qt::LeftButton) | | |||
160 | return XCB_BUTTON_INDEX_1; | | |||
161 | else if (button == Qt::MidButton) | | |||
162 | return XCB_BUTTON_INDEX_2; | | |||
163 | else if (button == Qt::RightButton) | | |||
164 | return XCB_BUTTON_INDEX_3; | | |||
165 | return XCB_BUTTON_INDEX_ANY; // 0 | | |||
166 | } | | |||
167 | | ||||
168 | Qt::MouseButton x11ToQtMouseButton(int button) | 152 | Qt::MouseButton x11ToQtMouseButton(int button) | ||
169 | { | 153 | { | ||
170 | if (button == XCB_BUTTON_INDEX_1) | 154 | if (button == XCB_BUTTON_INDEX_1) | ||
171 | return Qt::LeftButton; | 155 | return Qt::LeftButton; | ||
172 | if (button == XCB_BUTTON_INDEX_2) | 156 | if (button == XCB_BUTTON_INDEX_2) | ||
173 | return Qt::MidButton; | 157 | return Qt::MidButton; | ||
174 | if (button == XCB_BUTTON_INDEX_3) | 158 | if (button == XCB_BUTTON_INDEX_3) | ||
175 | return Qt::RightButton; | 159 | return Qt::RightButton; | ||
176 | if (button == XCB_BUTTON_INDEX_4) | 160 | if (button == XCB_BUTTON_INDEX_4) | ||
177 | return Qt::XButton1; | 161 | return Qt::XButton1; | ||
178 | if (button == XCB_BUTTON_INDEX_5) | 162 | if (button == XCB_BUTTON_INDEX_5) | ||
179 | return Qt::XButton2; | 163 | return Qt::XButton2; | ||
180 | return Qt::NoButton; | 164 | return Qt::NoButton; | ||
181 | } | 165 | } | ||
182 | 166 | | |||
183 | int qtToX11State(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) | | |||
184 | { | | |||
185 | int ret = 0; | | |||
186 | if (buttons & Qt::LeftButton) | | |||
187 | ret |= XCB_KEY_BUT_MASK_BUTTON_1; | | |||
188 | if (buttons & Qt::MidButton) | | |||
189 | ret |= XCB_KEY_BUT_MASK_BUTTON_2; | | |||
190 | if (buttons & Qt::RightButton) | | |||
191 | ret |= XCB_KEY_BUT_MASK_BUTTON_3; | | |||
192 | if (modifiers & Qt::ShiftModifier) | | |||
193 | ret |= XCB_KEY_BUT_MASK_SHIFT; | | |||
194 | if (modifiers & Qt::ControlModifier) | | |||
195 | ret |= XCB_KEY_BUT_MASK_CONTROL; | | |||
196 | if (modifiers & Qt::AltModifier) | | |||
197 | ret |= KKeyServer::modXAlt(); | | |||
198 | if (modifiers & Qt::MetaModifier) | | |||
199 | ret |= KKeyServer::modXMeta(); | | |||
200 | return ret; | | |||
201 | } | | |||
202 | | ||||
203 | Qt::MouseButtons x11ToQtMouseButtons(int state) | 167 | Qt::MouseButtons x11ToQtMouseButtons(int state) | ||
204 | { | 168 | { | ||
205 | Qt::MouseButtons ret = 0; | 169 | Qt::MouseButtons ret = 0; | ||
206 | if (state & XCB_KEY_BUT_MASK_BUTTON_1) | 170 | if (state & XCB_KEY_BUT_MASK_BUTTON_1) | ||
207 | ret |= Qt::LeftButton; | 171 | ret |= Qt::LeftButton; | ||
208 | if (state & XCB_KEY_BUT_MASK_BUTTON_2) | 172 | if (state & XCB_KEY_BUT_MASK_BUTTON_2) | ||
209 | ret |= Qt::MidButton; | 173 | ret |= Qt::MidButton; | ||
210 | if (state & XCB_KEY_BUT_MASK_BUTTON_3) | 174 | if (state & XCB_KEY_BUT_MASK_BUTTON_3) | ||
Show All 26 Lines |