KHtml

kxeventutil.cpp
1 // -*- c++ -*-
2 /* This file is part of the KDE project
3  *
4  * Copyright (C) 2002 Till Krech <[email protected]>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #include "kxeventutil.h"
23 
24 #include <X11/Xutil.h>
25 #include <X11/Xatom.h>
26 #include <QStringList>
27 
28 QString KXEventUtil::getXAnyEventInfo(XEvent *xevent)
29 {
30  XAnyEvent *e = &xevent->xany;
31  QString winname("window");
32  switch (e->type) {
33  case GraphicsExpose:
34  case NoExpose:
35  winname = "drawable";
36  break;
37  case CreateNotify:
38  case ConfigureRequest:
39  winname = "parent";
40  break;
41  case DestroyNotify:
42  case ConfigureNotify:
43  case MapNotify:
44  case ReparentNotify:
45  case UnmapNotify:
46  winname = "event";
47  default:
48  break;
49  }
50  QString s("serial=%1 send_event=%2 display=0x%3 %4=%5");
51  return
52  s.arg(e->serial)
53  .arg(e->send_event)
54  .arg((long)e->display, 0, 16)
55  .arg(winname)
56  .arg(e->window);
57 }
58 QString KXEventUtil::getXButtonEventInfo(XEvent *xevent)
59 {
60  XButtonEvent *e = &xevent->xbutton;
61  QString s("root=%1 subwindow=%2 time=%3 x=%4 y=%5 x_root=%6 y_root=%7 state=%8 button=%9");
62  QString t(" same_screen=%1");
63  return
64  s.arg(e->root)
65  .arg(e->subwindow)
66  .arg(e->time)
67  .arg(e->x)
68  .arg(e->y)
69  .arg(e->x_root)
70  .arg(e->y_root)
71  .arg(e->state)
72  .arg(e->button)
73  + t.arg(e->same_screen);
74 }
75 
76 QString KXEventUtil::getXKeyEventInfo(XEvent *xevent)
77 {
78  XKeyEvent *e = &xevent->xkey;
79  QString s("root=%1 subwindow=%2 time=%3 x=%4 y=%5 x_root=%6 y_root=%7 state=%8 keycode=%9");
80  QString t(" same_screen=%1");
81  return
82  s.arg(e->root)
83  .arg(e->subwindow)
84  .arg(e->time)
85  .arg(e->x)
86  .arg(e->y)
87  .arg(e->x_root)
88  .arg(e->y_root)
89  .arg(e->state)
90  .arg(e->keycode)
91  + t.arg(e->same_screen);
92 }
93 
94 QString KXEventUtil::getXMotionEventInfo(XEvent *xevent)
95 {
96  XMotionEvent *e = &xevent->xmotion;
97  QString s("root=%1 subwindow=%2 time=%3 x=%4 y=%5 x_root=%6 y_root=%7 state=%8 is_hint=%9");
98  QString t(" same_screen=%1");
99  return
100  s.arg(e->root)
101  .arg(e->subwindow)
102  .arg(e->time)
103  .arg(e->x)
104  .arg(e->y)
105  .arg(e->x_root)
106  .arg(e->y_root)
107  .arg(e->state)
108  .arg(e->is_hint)
109  + t.arg(e->same_screen);
110 }
111 QString KXEventUtil::getXCrossingEventInfo(XEvent *xevent)
112 {
113  XCrossingEvent *e = &xevent->xcrossing;
114  QString ms, ds;
115  switch (e->mode) {
116  case NotifyNormal: ms = "NotifyNormal"; break;
117  case NotifyGrab: ms = "NotifyGrab"; break;
118  case NotifyUngrab: ms = "NotifyUngrab"; break;
119  default: ms = "?";
120  }
121  switch (e->detail) {
122  case NotifyAncestor: ds = "NotifyAncestor"; break;
123  case NotifyVirtual: ds = "NotifyVirtual"; break;
124  case NotifyInferior: ds = "NotifyInferior"; break;
125  case NotifyNonlinear: ds = "NotifyNonlinear"; break;
126  case NotifyNonlinearVirtual: ds = "NotifyNonlinearVirtual"; break;
127  default: ds = "?";
128  }
129 
130  QString s("root=%1 subwindow=%2 time=%3 x=%4 y=%5 x_root=%6 y_root=%7 mode=%8=%9 ");
131  QString t("detail=%1=%2 same_screen=%3 focus=%4 state=%5");
132  return
133  s.arg(e->root)
134  .arg(e->subwindow)
135  .arg(e->time)
136  .arg(e->x)
137  .arg(e->y)
138  .arg(e->x_root)
139  .arg(e->y_root)
140  .arg(e->mode).arg(ms)
141  +
142  t.arg(e->detail).arg(ds)
143  .arg(e->same_screen)
144  .arg(e->focus)
145  .arg(e->state);
146 }
147 QString KXEventUtil::getXFocusChangeEventInfo(XEvent *xevent)
148 {
149  XFocusChangeEvent *e = &xevent->xfocus;
150  QString s("mode=%1 detail=%2");
151  return
152  s.arg(e->mode)
153  .arg(e->detail);
154 }
155 QString KXEventUtil::getXExposeEventInfo(XEvent *xevent)
156 {
157  XExposeEvent *e = &xevent->xexpose;
158  QString s("x=%1 y=%2 width=%3 height=%4 count=%5");
159  return
160  s.arg(e->x)
161  .arg(e->y)
162  .arg(e->width)
163  .arg(e->height)
164  .arg(e->count);
165 }
166 
167 QString KXEventUtil::getXGraphicsExposeEventInfo(XEvent *xevent)
168 {
169  XGraphicsExposeEvent *e = &xevent->xgraphicsexpose;
170  QString s("x=%1 y=%2 width=%3 height=%4 count=%5 major_code=%6 minor_code=%7");
171  return
172  s.arg(e->x)
173  .arg(e->y)
174  .arg(e->width)
175  .arg(e->height)
176  .arg(e->count)
177  .arg(e->major_code)
178  .arg(e->minor_code);
179 }
180 QString KXEventUtil::getXNoExposeEventInfo(XEvent *xevent)
181 {
182  XNoExposeEvent *e = &xevent->xnoexpose;
183  QString s("major_code=%1 minor_code=%2");
184  return
185  s.arg(e->major_code)
186  .arg(e->minor_code);
187 }
188 
189 QString KXEventUtil::getXCreateWindowEventInfo(XEvent *xevent)
190 {
191  XCreateWindowEvent *e = &xevent->xcreatewindow;
192  QString s("window=%1 x=%2 y=%3 width=%4 height=%5 border_width=%6 override_redirect=%7");
193  return
194  s.arg(e->window)
195  .arg(e->x)
196  .arg(e->y)
197  .arg(e->width)
198  .arg(e->height)
199  .arg(e->border_width)
200  .arg(e->override_redirect);
201 }
202 
203 QString KXEventUtil::getXDestroyWindowEventInfo(XEvent *xevent)
204 {
205  XDestroyWindowEvent *e = &xevent->xdestroywindow;
206  QString s("window=%1");
207  return
208  s.arg(e->window);
209 }
210 QString KXEventUtil::getXMapEventInfo(XEvent *xevent)
211 {
212  XMapEvent *e = &xevent->xmap;
213  QString s("window=%1 override_redirect=%2");
214  return
215  s.arg(e->window)
216  .arg(e->override_redirect);
217 }
218 QString KXEventUtil::getXMappingEventInfo(XEvent *xevent)
219 {
220  XMappingEvent *e = &xevent->xmapping;
221  QString s("request=%1 first_keycode=%2 count=%3");
222  return
223  s.arg(e->request)
224  .arg(e->first_keycode)
225  .arg(e->count);
226 }
227 QString KXEventUtil::getXReparentEventInfo(XEvent *xevent)
228 {
229  XReparentEvent *e = &xevent->xreparent;
230  QString s("window=%1 parent=%2 x=%3 y=%4");
231  return
232  s.arg(e->window)
233  .arg(e->parent)
234  .arg(e->x)
235  .arg(e->y);
236 }
237 QString KXEventUtil::getXUnmapEventInfo(XEvent *xevent)
238 {
239  XUnmapEvent *e = &xevent->xunmap;
240  QString s("window=%1 from_configure=%2");
241  return
242  s.arg(e->window)
243  .arg(e->from_configure);
244 }
245 
246 QString KXEventUtil::getXConfigureEventInfo(XEvent *xevent)
247 {
248  XConfigureEvent *e = &xevent->xconfigure;
249  QString s("window=%1 x=%2 y=%2 width=%3 height=%4 border_width=%5 above=%6 override_redirect=%7");
250  return
251  s.arg(e->window)
252  .arg(e->x).arg(e->y)
253  .arg(e->width).arg(e->height)
254  .arg(e->border_width)
255  .arg(e->above)
256  .arg(e->override_redirect);
257 }
258 
259 QString KXEventUtil::getXConfigureRequestEventInfo(XEvent *xevent)
260 {
261  XConfigureRequestEvent *e = &xevent->xconfigurerequest;
262  unsigned vm = e->value_mask;
263  QStringList vml;
264  if (vm & CWX) {
265  vml.append("CWX");
266  }
267  if (vm & CWY) {
268  vml.append("CWY");
269  }
270  if (vm & CWWidth) {
271  vml.append("CWWidth");
272  }
273  if (vm & CWHeight) {
274  vml.append("CWHeight");
275  }
276  if (vm & CWBorderWidth) {
277  vml.append("CWBorderWidth");
278  }
279  if (vm & CWSibling) {
280  vml.append("CWSibling");
281  }
282  if (vm & CWStackMode) {
283  vml.append("CWStackMode");
284  }
285  QString vms = vml.join("|");
286  QString s("window=%1 x=%2 y=%2 width=%3 height=%4 border_width=%5 above=%6 detail=%7 value_mask=0x%8=%9");
287  return
288  s.arg(e->window)
289  .arg(e->x).arg(e->y)
290  .arg(e->width).arg(e->height)
291  .arg(e->border_width)
292  .arg(e->above)
293  .arg(e->detail)
294  .arg(e->value_mask, 0, 16)
295  .arg(vms);
296 }
297 QString KXEventUtil::getX11EventInfo(XEvent *e)
298 {
299  QString anyInfo = getXAnyEventInfo(e);
300  QString info = "";
301  QString s;
302  switch (e->type) {
303  case KeyPress:
304  s = "KeyPress";
305  info = getXKeyEventInfo(e);
306  break;
307  case KeyRelease:
308  s = "KeyRelease";
309  info = getXKeyEventInfo(e);
310  break;
311  case ButtonPress:
312  s = "ButtonPress";
313  info = getXButtonEventInfo(e);
314  break;
315  case ButtonRelease:
316  s = "ButtonRelease";
317  info = getXButtonEventInfo(e);
318  break;
319  case MotionNotify:
320  s = "MotionNotify";
321  info = getXMotionEventInfo(e);
322  break;
323  case EnterNotify:
324  s = "EnterNotify";
325  info = getXCrossingEventInfo(e);
326  break;
327  case LeaveNotify:
328  s = "LeaveNotify";
329  info = getXCrossingEventInfo(e);
330  break;
331  case FocusIn:
332  s = "FocusIn";
333  info = getXFocusChangeEventInfo(e);
334  break;
335  case FocusOut:
336  s = "FocusOut";
337  info = getXFocusChangeEventInfo(e);
338  break;
339  case KeymapNotify:
340  s = "KeymapNotify";
341  break;
342  case Expose:
343  s = "Expose";
344  info = getXExposeEventInfo(e);
345  break;
346  case GraphicsExpose:
347  s = "GraphicsExpose";
348  info = getXGraphicsExposeEventInfo(e);
349  break;
350  case NoExpose:
351  info = getXNoExposeEventInfo(e);
352  s = "NoExpose";
353  break;
354  case VisibilityNotify:
355  s = "VisibilityNotify";
356  break;
357  case CreateNotify:
358  s = "CreateNotify";
359  info = getXCreateWindowEventInfo(e);
360  break;
361  case DestroyNotify:
362  s = "DestroyNotify";
363  info = getXDestroyWindowEventInfo(e);
364  break;
365  case UnmapNotify:
366  s = "UnmapNotify";
367  info = getXUnmapEventInfo(e);
368  break;
369  case MapNotify:
370  s = "MapNotify";
371  info = getXMapEventInfo(e);
372  break;
373  case MapRequest:
374  s = "MapRequest";
375  break;
376  case ReparentNotify:
377  s = "ReparentNotify";
378  info = getXReparentEventInfo(e);
379  break;
380  case ConfigureNotify:
381  s = "ConfigureNotify";
382  info = getXConfigureEventInfo(e);
383  break;
384  case ConfigureRequest:
385  s = "ConfigureRequest";
386  info = getXConfigureRequestEventInfo(e);
387  break;
388  case GravityNotify:
389  s = "GravityNotify";
390  break;
391  case ResizeRequest:
392  s = "ResizeRequest";
393  break;
394  case CirculateNotify:
395  s = "CirculateNofify";
396  break;
397  case CirculateRequest:
398  s = "CirculateRequest";
399  break;
400  case PropertyNotify:
401  s = "PropertyNotify";
402  break;
403  case SelectionClear:
404  s = "SelectionClear";
405  break;
406  case SelectionRequest:
407  s = "SelectionRequest";
408  break;
409  case SelectionNotify:
410  s = "SelectionNotify";
411  break;
412  case ColormapNotify:
413  s = "ColormapNotify";
414  break;
415  case ClientMessage:
416  s = "ClientMessage";
417  break;
418  case MappingNotify:
419  s = "MappingNotify";
420  info = getXMappingEventInfo(e);
421  break;
422  case LASTEvent:
423  s = "LASTEvent";
424  break;
425 
426  default:
427  s = "Undefined";
428  break;
429  }
430 
431  return s + ' ' + anyInfo + ' ' + info;
432 }
QString join(const QString &separator) const const
void append(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.