summaryrefslogtreecommitdiff
blob: 750edf2fefa081970cb7479cd8c87dbe95c1b669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
diff -bBurN root-tail-1.2/config.h root-tail-my/config.h
--- root-tail-1.2/config.h	2004-07-30 23:32:39.000000000 +0400
+++ root-tail-my/config.h	2005-02-23 13:02:48.878912688 +0300
@@ -15,3 +15,4 @@
 
 #define VERSION "1.2"
 
+#define KDE
diff -bBurN root-tail-1.2/root-tail.c root-tail-my/root-tail.c
--- root-tail-1.2/root-tail.c	2004-07-30 23:33:20.000000000 +0400
+++ root-tail-my/root-tail.c	2005-02-23 13:02:37.599627400 +0300
@@ -148,6 +148,11 @@
 regex_t *transformre;
 #endif
 
+#ifdef KDE
+#define ATOM(a) XInternAtom(disp, #a, False)
+
+int screen, ScreenWidth, ScreenHeight;
+#endif
 
 /* prototypes */
 void list_files (int);
@@ -227,7 +232,7 @@
   return Color.pixel;
 }
 
-#ifndef USE_TOON_GET_ROOT_WINDOW
+#if !defined(USE_TOON_GET_ROOT_WINDOW) && !defined(KDE)
 static void
 find_root_window (Display *display, int screen_number)
 {
@@ -280,14 +285,91 @@
         fprintf (stderr, "Can't query tree on root window 0x%lx", root);
     }
 }
-#endif /* USE_TOON_GET_ROOT_WINDOW */
+#elif defined(KDE)
+static Window find_subwindow(Window win, int w, int h) {
+  unsigned int i, j;
+  Window troot, parent, *children;
+  unsigned int n;
+
+  /* search subwindows with same size as display or work area */
+
+  for (i=0; i<10; i++) {
+    XQueryTree(disp, win, &troot, &parent, &children, &n);
+
+    for (j=0; j<n; j++) {
+      XWindowAttributes attrs;
+
+      if (XGetWindowAttributes(disp, children[j], &attrs)) {
+        /* Window must be mapped and same size as display or work space */
+        if (attrs.map_state != 0 &&
+            ((attrs.width == ScreenWidth && attrs.height == ScreenHeight) ||
+             (attrs.width == w && attrs.height == h))) {
+          win = children[j];
+          break;
+        }
+      }
+    }
+
+    XFree(children);
+    if (j == n) break;
+  }
+
+  return win;
+}
+
+static void
+find_root_window (Display *display, int screen_number)
+{
+  Atom type;
+  int format, i;
+  unsigned long nitems, bytes;
+  unsigned int n;
+  root = RootWindow(display, screen_number);
+  Window win = root;
+  Window troot, parent, *children;
+  unsigned char *buf = NULL;
+
+  /* some window managers set __SWM_VROOT to some child of root window */
+
+  XQueryTree(display, root, &troot, &parent, &children, &n);
+  for (i=0; i<(int)n; i++) {
+    if (XGetWindowProperty(display, children[i], ATOM(__SWM_VROOT),
+          0, 1, False, XA_WINDOW, &type, &format, &nitems, &bytes,
+          &buf) == Success && type == XA_WINDOW) {
+      win = * (Window *) buf;
+      XFree(buf);
+      XFree(children);
+      fprintf(stderr, "torsmo: drawing to window from __SWM_VROOT property\n");
+      root=win;
+      return;
+    }
+
+    if (buf) {
+      XFree(buf);
+      buf = 0;
+    }
+  }
+  XFree(children);
+
+  /* get subwindows from root */
+  win = find_subwindow(root, -1, -1);
+
+  win = find_subwindow(win, width, height);
+
+  if (buf) { XFree(buf); buf = 0; }
+
+  root=win;
+}
+#endif /* USE_TOON_GET_ROOT_WINDOW && KDE*/
 
 void
 InitWindow (void)
 {
   XGCValues gcv;
   unsigned long gcm;
+#ifndef KDE
   int screen, ScreenWidth, ScreenHeight;
+#endif
   struct logfile_entry *e;
 
   if (!(disp = XOpenDisplay (dispname)))