summaryrefslogtreecommitdiff
path: root/src/preload
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2005-06-02 14:56:07 +0000
committerCarsten Haitzler <raster@rasterman.com>2005-06-02 14:56:07 +0000
commit2005381bbdf305a7d86b2f309e6ec28a613d976b (patch)
treeeaf35bf8369ecd0f0ce124678b7fb5eb408a8b40 /src/preload
parentc55341c52bdc5cd28052347e4fca74e69096694c (diff)
ehack is baaack! :)
SVN revision: 15057
Diffstat (limited to 'src/preload')
-rw-r--r--src/preload/Makefile.am15
-rw-r--r--src/preload/e_hack.c218
-rw-r--r--src/preload/e_hack.h12
3 files changed, 245 insertions, 0 deletions
diff --git a/src/preload/Makefile.am b/src/preload/Makefile.am
new file mode 100644
index 000000000..c08c6b23b
--- /dev/null
+++ b/src/preload/Makefile.am
@@ -0,0 +1,15 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3INCLUDES = -I. \
4 -I$(top_srcdir) \
5 -I$(includedir) \
6 -I$(top_srcdir)src/preload \
7 @x_cflags@
8pkgdir = $(libdir)/enlightenment/preload
9pkg_LTLIBRARIES = e_hack.la
10e_hack_la_SOURCES = \
11e_hack.c \
12e_hack.h
13e_hack_la_LIBADD = @x_libs@ @dlopen_libs@
14e_hack_la_LDFLAGS = -module -avoid-version
15e_hack_la_DEPENDENCIES = $(top_builddir)/config.h
diff --git a/src/preload/e_hack.c b/src/preload/e_hack.c
new file mode 100644
index 000000000..a21ed19c8
--- /dev/null
+++ b/src/preload/e_hack.c
@@ -0,0 +1,218 @@
1#include "config.h"
2#include "e_hack.h"
3
4/* prototypes */
5static void __e_hack_set_properties(Display *display, Window window);
6
7/* dlopened xlib so we can find the symbols in the real xlib to call them */
8static void *lib_xlib = NULL;
9
10/* the function that actually sets the properties on toplevel window */
11static void
12__e_hack_set_properties(Display *display, Window window)
13{
14 static Atom a_launch_id = 0;
15 static Atom a_user_id = 0;
16 static Atom a_process_id = 0;
17 static Atom a_p_process_id = 0;
18 static Atom a_machine_name = 0;
19 static Atom a_user_name = 0;
20 static Atom a_desk = 0;
21 static Atom a_zone = 0;
22 static Atom a_container = 0;
23 static Atom a_manager = 0;
24 char *env = NULL;
25
26 if (!a_launch_id) a_launch_id = XInternAtom(display, "_E_HACK_LAUNCH_ID", False);
27 if (!a_user_id) a_user_id = XInternAtom(display, "_E_HACK_USER_ID", False);
28 if (!a_process_id) a_process_id = XInternAtom(display, "_E_HACK_PROCESS_ID", False);
29 if (!a_p_process_id) a_p_process_id = XInternAtom(display, "_E_HACK_PARENT_PROCESS_ID", False);
30 if (!a_machine_name) a_machine_name = XInternAtom(display, "_E_HACK_MACHINE_NAME", False);
31 if (!a_user_name) a_user_name = XInternAtom(display, "_E_HACK_USER_NAME", False);
32 if (!a_desk) a_desk = XInternAtom(display, "_E_HACK_DESK", False);
33 if (!a_zone) a_zone = XInternAtom(display, "_E_HACK_ZONE", False);
34 if (!a_container) a_container = XInternAtom(display, "_E_HACK_CONTAINER", False);
35 if (!a_manager) a_manager = XInternAtom(display, "_E_HACK_MANAGER", False);
36
37 if ((env = getenv("E_LAUNCH_ID")))
38 XChangeProperty(display, window, a_launch_id, XA_STRING, 8, PropModeReplace, env, strlen(env));
39 {
40 uid_t uid;
41 pid_t pid, ppid;
42 struct utsname ubuf;
43 char buf[4096];
44
45 uid = getuid();
46 pid = getpid();
47 ppid = getppid();
48
49 snprintf(buf, sizeof(buf), "%i", uid);
50 XChangeProperty(display, window, a_user_id, XA_STRING, 8, PropModeReplace, buf, strlen(buf));
51 snprintf(buf, sizeof(buf), "%i", pid);
52 XChangeProperty(display, window, a_process_id, XA_STRING, 8, PropModeReplace, buf, strlen(buf));
53 snprintf(buf, sizeof(buf), "%i", ppid);
54 XChangeProperty(display, window, a_p_process_id, XA_STRING, 8, PropModeReplace, buf, strlen(buf));
55 if (!uname(&ubuf))
56 {
57 snprintf(buf, sizeof(buf), "%s", ubuf.nodename);
58 XChangeProperty(display, window, a_machine_name, XA_STRING, 8, PropModeReplace, buf, strlen(buf));
59 }
60 else
61 XChangeProperty(display, window, a_machine_name, XA_STRING, 8, PropModeReplace, " ", 1);
62 }
63 if ((env = getenv("USER")))
64 XChangeProperty(display, window, a_user_name, XA_STRING, 8, PropModeReplace, env, strlen(env));
65 if ((env = getenv("E_DESK")))
66 XChangeProperty(display, window, a_desk, XA_STRING, 8, PropModeReplace, env, strlen(env));
67 if ((env = getenv("E_ZONE")))
68 XChangeProperty(display, window, a_zone, XA_STRING, 8, PropModeReplace, env, strlen(env));
69 if ((env = getenv("E_CONTAINER")))
70 XChangeProperty(display, window, a_container, XA_STRING, 8, PropModeReplace, env, strlen(env));
71 if ((env = getenv("E_MANAGER")))
72 XChangeProperty(display, window, a_manager, XA_STRING, 8, PropModeReplace, env, strlen(env));
73}
74
75/* XCreateWindow intercept hack */
76Window
77XCreateWindow(
78 Display *display,
79 Window parent,
80 int x, int y,
81 unsigned int width, unsigned int height,
82 unsigned int border_width,
83 int depth,
84 unsigned int class,
85 Visual *visual,
86 unsigned long valuemask,
87 XSetWindowAttributes *attributes
88 )
89{
90 static Window (*func)
91 (
92 Display *display,
93 Window parent,
94 int x, int y,
95 unsigned int width, unsigned int height,
96 unsigned int border_width,
97 int depth,
98 unsigned int class,
99 Visual *visual,
100 unsigned long valuemask,
101 XSetWindowAttributes *attributes
102 ) = NULL;
103 int i;
104
105 /* find the real Xlib and the real X function */
106 if (!lib_xlib) lib_xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
107 if (!func) func = dlsym (lib_xlib, "XCreateWindow");
108
109 /* multihead screen handling loop */
110 for (i = 0; i < ScreenCount(display); i++)
111 {
112 /* if the window is created as a toplevel window */
113 if (parent == RootWindow(display, i))
114 {
115 Window window;
116
117 /* create it */
118 window = (*func) (display, parent, x, y, width, height,
119 border_width, depth, class, visual, valuemask,
120 attributes);
121 /* set properties */
122 __e_hack_set_properties(display, window);
123 /* return it */
124 return window;
125 }
126 }
127 /* normal child window - create as usual */
128 return (*func) (display, parent, x, y, width, height, border_width, depth,
129 class, visual, valuemask, attributes);
130}
131
132/* XCreateSimpleWindow intercept hack */
133Window
134XCreateSimpleWindow(
135 Display *display,
136 Window parent,
137 int x, int y,
138 unsigned int width, unsigned int height,
139 unsigned int border_width,
140 unsigned long border,
141 unsigned long background
142 )
143{
144 static Window (*func)
145 (
146 Display *display,
147 Window parent,
148 int x, int y,
149 unsigned int width, unsigned int height,
150 unsigned int border_width,
151 unsigned long border,
152 unsigned long background
153 ) = NULL;
154 int i;
155
156 /* find the real Xlib and the real X function */
157 if (!lib_xlib) lib_xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
158 if (!func) func = dlsym (lib_xlib, "XCreateSimpleWindow");
159
160 /* multihead screen handling loop */
161 for (i = 0; i < ScreenCount(display); i++)
162 {
163 /* if the window is created as a toplevel window */
164 if (parent == RootWindow(display, i))
165 {
166 Window window;
167
168 /* create it */
169 window = (*func) (display, parent, x, y, width, height,
170 border_width, border, background);
171 /* set properties */
172 __e_hack_set_properties(display, window);
173 /* return it */
174 return window;
175 }
176 }
177 /* normal child window - create as usual */
178 return (*func) (display, parent, x, y, width, height,
179 border_width, border, background);
180}
181
182/* XReparentWindow intercept hack */
183int
184XReparentWindow(
185 Display *display,
186 Window window,
187 Window parent,
188 int x, int y
189 )
190{
191 static int (*func)
192 (
193 Display *display,
194 Window window,
195 Window parent,
196 int x, int y
197 ) = NULL;
198 int i;
199
200 /* find the real Xlib and the real X function */
201 if (!lib_xlib) lib_xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
202 if (!func) func = dlsym (lib_xlib, "XReparentWindow");
203
204 /* multihead screen handling loop */
205 for (i = 0; i < ScreenCount(display); i++)
206 {
207 /* if the window is created as a toplevel window */
208 if (parent == RootWindow(display, i))
209 {
210 /* set properties */
211 __e_hack_set_properties(display, window);
212 /* reparent it */
213 return (*func) (display, window, parent, x, y);
214 }
215 }
216 /* normal child window reparenting - reparent as usual */
217 return (*func) (display, window, parent, x, y);
218}
diff --git a/src/preload/e_hack.h b/src/preload/e_hack.h
new file mode 100644
index 000000000..a2948c95d
--- /dev/null
+++ b/src/preload/e_hack.h
@@ -0,0 +1,12 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <stdarg.h>
4#include <string.h>
5#include <dlfcn.h>
6#include <unistd.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <sys/utsname.h>
10#include <X11/Xlib.h>
11#include <X11/X.h>
12#include <X11/Xatom.h>