OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 if (!select(x11_fd + 1, &input_fds, NULL, NULL, &tv)) { | 193 if (!select(x11_fd + 1, &input_fds, NULL, NULL, &tv)) { |
194 if (!XPending(dsp)) { | 194 if (!XPending(dsp)) { |
195 return false; | 195 return false; |
196 } | 196 } |
197 } | 197 } |
198 } | 198 } |
199 XNextEvent(dsp, evt); | 199 XNextEvent(dsp, evt); |
200 return true; | 200 return true; |
201 } | 201 } |
202 | 202 |
| 203 static Atom wm_delete_window_message; |
| 204 |
203 SkOSWindow::NextXEventResult SkOSWindow::nextXEvent() { | 205 SkOSWindow::NextXEventResult SkOSWindow::nextXEvent() { |
204 XEvent evt; | 206 XEvent evt; |
205 Display* dsp = fUnixWindow.fDisplay; | 207 Display* dsp = fUnixWindow.fDisplay; |
206 | 208 |
207 if (!MyXNextEventWithDelay(fUnixWindow.fDisplay, &evt)) { | 209 if (!MyXNextEventWithDelay(dsp, &evt)) { |
208 return kContinue_NextXEventResult; | 210 return kContinue_NextXEventResult; |
209 } | 211 } |
210 | 212 |
211 switch (evt.type) { | 213 switch (evt.type) { |
212 case Expose: | 214 case Expose: |
213 if (0 == evt.xexpose.count) { | 215 if (0 == evt.xexpose.count) { |
214 return kPaintRequest_NextXEventResult; | 216 return kPaintRequest_NextXEventResult; |
215 } | 217 } |
216 break; | 218 break; |
217 case ConfigureNotify: | 219 case ConfigureNotify: |
(...skipping 23 matching lines...) Expand all Loading... |
241 this->handleKey(XKeyToSkKey(keysym)); | 243 this->handleKey(XKeyToSkKey(keysym)); |
242 long uni = keysym2ucs(keysym); | 244 long uni = keysym2ucs(keysym); |
243 if (uni != -1) { | 245 if (uni != -1) { |
244 this->handleChar((SkUnichar) uni); | 246 this->handleChar((SkUnichar) uni); |
245 } | 247 } |
246 break; | 248 break; |
247 } | 249 } |
248 case KeyRelease: | 250 case KeyRelease: |
249 this->handleKeyUp(XKeyToSkKey(XkbKeycodeToKeysym(dsp, evt.xkey.keyco
de, 0, 0))); | 251 this->handleKeyUp(XKeyToSkKey(XkbKeycodeToKeysym(dsp, evt.xkey.keyco
de, 0, 0))); |
250 break; | 252 break; |
| 253 case ClientMessage: |
| 254 if ((Atom)evt.xclient.data.l[0] == wm_delete_window_message) { |
| 255 return kQuitRequest_NextXEventResult; |
| 256 } |
| 257 // fallthrough |
251 default: | 258 default: |
252 // Do nothing for other events | 259 // Do nothing for other events |
253 break; | 260 break; |
254 } | 261 } |
255 return kContinue_NextXEventResult; | 262 return kContinue_NextXEventResult; |
256 } | 263 } |
257 | 264 |
258 void SkOSWindow::loop() { | 265 void SkOSWindow::loop() { |
259 Display* dsp = fUnixWindow.fDisplay; | 266 Display* dsp = fUnixWindow.fDisplay; |
260 if (NULL == dsp) { | 267 if (NULL == dsp) { |
261 return; | 268 return; |
262 } | 269 } |
263 Window win = fUnixWindow.fWin; | 270 Window win = fUnixWindow.fWin; |
264 | 271 |
| 272 wm_delete_window_message = XInternAtom(dsp, "WM_DELETE_WINDOW", False); |
| 273 XSetWMProtocols(dsp, win, &wm_delete_window_message, 1); |
| 274 |
265 XSelectInput(dsp, win, EVENT_MASK); | 275 XSelectInput(dsp, win, EVENT_MASK); |
266 | 276 |
267 bool sentExposeEvent = false; | 277 bool sentExposeEvent = false; |
268 | 278 |
269 for (;;) { | 279 for (;;) { |
270 SkEvent::ServiceQueueTimer(); | 280 SkEvent::ServiceQueueTimer(); |
271 | 281 |
272 bool moreToDo = SkEvent::ProcessEvent(); | 282 bool moreToDo = SkEvent::ProcessEvent(); |
273 | 283 |
274 if (this->isDirty() && !sentExposeEvent) { | 284 if (this->isDirty() && !sentExposeEvent) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 431 |
422 void SkEvent::SignalNonEmptyQueue() { | 432 void SkEvent::SignalNonEmptyQueue() { |
423 // nothing to do, since we spin on our event-queue, polling for XPending | 433 // nothing to do, since we spin on our event-queue, polling for XPending |
424 } | 434 } |
425 | 435 |
426 void SkEvent::SignalQueueTimer(SkMSec delay) { | 436 void SkEvent::SignalQueueTimer(SkMSec delay) { |
427 // just need to record the delay time. We handle waking up for it in | 437 // just need to record the delay time. We handle waking up for it in |
428 // MyXNextEventWithDelay() | 438 // MyXNextEventWithDelay() |
429 gTimerDelay = delay; | 439 gTimerDelay = delay; |
430 } | 440 } |
OLD | NEW |