chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / src / extinitwin.c
1 /*
2  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3  * Copyright (C) 2004-2008 Kim Woelders
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies of the Software, its documentation and marketing & publicity
14  * materials, and acknowledgment shall be given in the documentation, materials
15  * and software packages that this Software was used.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #include "E.h"
25 #include "e16-ecore_hints.h"
26 #include "eimage.h"
27 #include "xwin.h"
28 #include <X11/Xutil.h>
29 #include <X11/extensions/shape.h>
30
31 static              Window
32 ExtInitWinMain(void)
33 {
34    int                 i, err;
35    Ecore_X_Window      win;
36    XGCValues           gcv;
37    GC                  gc;
38    Pixmap              pmap, mask;
39    Atom                a;
40    XSetWindowAttributes attr;
41
42    if (EDebug(EDBUG_TYPE_SESSION))
43       Eprintf("ExtInitWinMain enter\n");
44
45    err = EDisplayOpen(NULL, -1);
46    if (err)
47       return None;
48
49    EGrabServer();
50
51    EImageInit();
52
53    attr.backing_store = NotUseful;
54    attr.override_redirect = True;
55    attr.colormap = WinGetCmap(VROOT);
56    attr.border_pixel = 0;
57    attr.background_pixel = 0;
58    attr.save_under = True;
59    win = XCreateWindow(disp, WinGetXwin(VROOT),
60                        0, 0, WinGetW(VROOT), WinGetH(VROOT),
61                        0, CopyFromParent, InputOutput, CopyFromParent,
62                        CWOverrideRedirect | CWSaveUnder | CWBackingStore |
63                        CWColormap | CWBackPixel | CWBorderPixel, &attr);
64
65    pmap = XCreatePixmap(disp, win,
66                         WinGetW(VROOT), WinGetH(VROOT), WinGetDepth(VROOT));
67    gcv.subwindow_mode = IncludeInferiors;
68    gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
69    XCopyArea(disp, WinGetXwin(VROOT), pmap, gc,
70              0, 0, WinGetW(VROOT), WinGetH(VROOT), 0, 0);
71    XSetWindowBackgroundPixmap(disp, win, pmap);
72    XMapRaised(disp, win);
73    XFreePixmap(disp, pmap);
74    XFreeGC(disp, gc);
75
76    a = EInternAtom("ENLIGHTENMENT_RESTART_SCREEN");
77    ecore_x_window_prop_window_set(WinGetXwin(VROOT), a, &win, 1);
78
79    XSelectInput(disp, win, StructureNotifyMask);
80
81    EUngrabServer();
82    ESync(0);
83
84    {
85       Window              w2, ww;
86       char                s[1024];
87       EImage             *im;
88       int                 dd, x, y, w, h;
89       unsigned int        mm;
90       Cursor              cs = 0;
91       XColor              cl;
92       XWindowAttributes   xwa;
93
94       w2 = XCreateWindow(disp, win, 0, 0, 32, 32, 0, CopyFromParent,
95                          InputOutput, CopyFromParent,
96                          CWOverrideRedirect | CWBackingStore | CWColormap |
97                          CWBackPixel | CWBorderPixel, &attr);
98
99       pmap = XCreatePixmap(disp, w2, 16, 16, 1);
100       gc = XCreateGC(disp, pmap, 0, NULL);
101       XSetForeground(disp, gc, 0);
102       XFillRectangle(disp, pmap, gc, 0, 0, 16, 16);
103       XFreeGC(disp, gc);
104
105       mask = XCreatePixmap(disp, w2, 16, 16, 1);
106       gc = XCreateGC(disp, mask, 0, NULL);
107       XSetForeground(disp, gc, 0);
108       XFillRectangle(disp, mask, gc, 0, 0, 16, 16);
109       XFreeGC(disp, gc);
110
111       cs = XCreatePixmapCursor(disp, pmap, mask, &cl, &cl, 0, 0);
112       XDefineCursor(disp, win, cs);
113       XDefineCursor(disp, w2, cs);
114
115       for (i = 1;; i++)
116         {
117            if (i > 12)
118               i = 1;
119
120            /* If we get unmapped we are done */
121            XGetWindowAttributes(disp, win, &xwa);
122            if (xwa.map_state == IsUnmapped)
123               break;
124
125            Esnprintf(s, sizeof(s), "pix/wait%i.png", i);
126            if (EDebug(EDBUG_TYPE_SESSION) > 1)
127               Eprintf("ExtInitWinCreate - child %s\n", s);
128
129            im = ThemeImageLoad(s);
130            if (im)
131              {
132                 EImageRenderPixmaps(im, NULL, 0, &pmap, &mask, 0, 0);
133                 EImageGetSize(im, &w, &h);
134                 XShapeCombineMask(disp, w2, ShapeBounding, 0, 0, mask,
135                                   ShapeSet);
136                 XSetWindowBackgroundPixmap(disp, w2, pmap);
137                 EImagePixmapsFree(pmap, mask);
138                 XClearWindow(disp, w2);
139                 XQueryPointer(disp, win, &ww, &ww, &dd, &dd, &x, &y, &mm);
140                 XMoveResizeWindow(disp, w2, x - w / 2, y - h / 2, w, h);
141                 XMapWindow(disp, w2);
142                 EImageFree(im);
143              }
144            usleep(50000);
145            ESync(0);
146         }
147    }
148
149    if (EDebug(EDBUG_TYPE_SESSION))
150       Eprintf("ExtInitWinMain exit\n");
151
152    EDisplayClose();
153
154    exit(0);
155 }
156
157 Window
158 ExtInitWinCreate(void)
159 {
160    Ecore_X_Window      win_ex;  /* Hmmm.. */
161    Window              win;
162    Atom                a;
163
164    if (EDebug(EDBUG_TYPE_SESSION))
165       Eprintf("ExtInitWinCreate\n");
166
167    a = EInternAtom("ENLIGHTENMENT_RESTART_SCREEN");
168    ESync(0);
169
170    if (fork())
171      {
172         /* Parent */
173         EUngrabServer();
174
175         for (;;)
176           {
177              if (EDebug(EDBUG_TYPE_SESSION))
178                 Eprintf("ExtInitWinCreate - parent\n");
179
180              /* Hack to give the child some space. Not foolproof. */
181              sleep(1);
182
183              if (ecore_x_window_prop_window_get
184                  (WinGetXwin(VROOT), a, &win_ex, 1) > 0)
185                 break;
186           }
187
188         win = win_ex;
189         if (EDebug(EDBUG_TYPE_SESSION))
190            Eprintf("ExtInitWinCreate - parent - %#lx\n", win);
191
192         return win;
193      }
194
195    /* Child - Create the init window */
196
197    if (EDebug(EDBUG_TYPE_SESSION))
198       Eprintf("ExtInitWinCreate - child\n");
199
200    /* Clean up inherited stuff */
201
202    SignalsRestore();
203
204    EImageExit(0);
205    EDisplayDisconnect();
206
207    ExtInitWinMain();
208
209    /* We will never get here */
210    return None;
211 }
212
213 static Window       init_win_ext = None;
214
215 void
216 ExtInitWinSet(Window win)
217 {
218    init_win_ext = win;
219 }
220
221 Window
222 ExtInitWinGet(void)
223 {
224    return init_win_ext;
225 }
226
227 void
228 ExtInitWinKill(void)
229 {
230    if (!disp || init_win_ext == None)
231       return;
232
233    if (EDebug(EDBUG_TYPE_SESSION))
234       Eprintf("Kill init window %#lx\n", init_win_ext);
235    XUnmapWindow(disp, init_win_ext);
236    init_win_ext = None;
237 }