e16/src/extinitwin.c

237 lines
6.2 KiB
C
Raw Normal View History

2004-12-28 15:46:49 -08:00
/*
2007-01-13 11:14:29 -08:00
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
2008-03-22 07:51:24 -07:00
* Copyright (C) 2004-2008 Kim Woelders
2004-12-28 15:46:49 -08:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of the Software, its documentation and marketing & publicity
* materials, and acknowledgment shall be given in the documentation, materials
* and software packages that this Software was used.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "E.h"
2006-02-18 01:50:17 -08:00
#include "e16-ecore_hints.h"
2006-03-29 11:13:17 -08:00
#include "eimage.h"
#include "xwin.h"
#include <X11/extensions/shape.h>
2004-12-28 15:46:49 -08:00
static Window
ExtInitWinMain(void)
{
int i, err;
Ecore_X_Window win;
2004-12-28 15:46:49 -08:00
XGCValues gcv;
GC gc;
Pixmap pmap, mask;
Atom a;
XSetWindowAttributes attr;
if (EDebug(EDBUG_TYPE_SESSION))
2004-12-28 15:46:49 -08:00
Eprintf("ExtInitWinMain enter\n");
err = EDisplayOpen(NULL, -1);
if (err)
return None;
2004-12-28 15:46:49 -08:00
EGrabServer();
2004-12-28 15:46:49 -08:00
EImageInit();
2004-12-28 15:46:49 -08:00
attr.backing_store = NotUseful;
attr.override_redirect = True;
attr.colormap = WinGetCmap(VROOT);
2004-12-28 15:46:49 -08:00
attr.border_pixel = 0;
attr.background_pixel = 0;
attr.save_under = True;
win = XCreateWindow(disp, WinGetXwin(VROOT),
0, 0, WinGetW(VROOT), WinGetH(VROOT),
0, CopyFromParent, InputOutput, CopyFromParent,
2004-12-28 15:46:49 -08:00
CWOverrideRedirect | CWSaveUnder | CWBackingStore |
CWColormap | CWBackPixel | CWBorderPixel, &attr);
pmap = XCreatePixmap(disp, win,
WinGetW(VROOT), WinGetH(VROOT), WinGetDepth(VROOT));
2004-12-28 15:46:49 -08:00
gcv.subwindow_mode = IncludeInferiors;
gc = XCreateGC(disp, win, GCSubwindowMode, &gcv);
XCopyArea(disp, WinGetXwin(VROOT), pmap, gc,
0, 0, WinGetW(VROOT), WinGetH(VROOT), 0, 0);
2004-12-28 15:46:49 -08:00
XSetWindowBackgroundPixmap(disp, win, pmap);
XMapRaised(disp, win);
XFreePixmap(disp, pmap);
XFreeGC(disp, gc);
2004-12-28 15:46:49 -08:00
a = EInternAtom("ENLIGHTENMENT_RESTART_SCREEN");
ecore_x_window_prop_window_set(WinGetXwin(VROOT), a, &win, 1);
2004-12-28 15:46:49 -08:00
XSelectInput(disp, win, StructureNotifyMask);
EUngrabServer();
ESync(0);
2004-12-28 15:46:49 -08:00
{
Window w2, ww;
char s[1024];
2006-03-29 11:13:17 -08:00
EImage *im;
int dd, x, y, w, h;
2004-12-28 15:46:49 -08:00
unsigned int mm;
Cursor cs = 0;
XColor cl;
XWindowAttributes xwa;
2004-12-28 15:46:49 -08:00
w2 = XCreateWindow(disp, win, 0, 0, 32, 32, 0, CopyFromParent,
InputOutput, CopyFromParent,
2004-12-28 15:46:49 -08:00
CWOverrideRedirect | CWBackingStore | CWColormap |
CWBackPixel | CWBorderPixel, &attr);
pmap = XCreatePixmap(disp, w2, 16, 16, 1);
gc = XCreateGC(disp, pmap, 0, NULL);
2004-12-28 15:46:49 -08:00
XSetForeground(disp, gc, 0);
XFillRectangle(disp, pmap, gc, 0, 0, 16, 16);
XFreeGC(disp, gc);
2004-12-28 15:46:49 -08:00
mask = XCreatePixmap(disp, w2, 16, 16, 1);
gc = XCreateGC(disp, mask, 0, NULL);
2004-12-28 15:46:49 -08:00
XSetForeground(disp, gc, 0);
XFillRectangle(disp, mask, gc, 0, 0, 16, 16);
XFreeGC(disp, gc);
2004-12-28 15:46:49 -08:00
cs = XCreatePixmapCursor(disp, pmap, mask, &cl, &cl, 0, 0);
XDefineCursor(disp, win, cs);
XDefineCursor(disp, w2, cs);
for (i = 1;; i++)
{
if (i > 12)
i = 1;
/* If we get unmapped we are done */
XGetWindowAttributes(disp, win, &xwa);
if (xwa.map_state == IsUnmapped)
break;
2004-12-28 15:46:49 -08:00
Esnprintf(s, sizeof(s), "pix/wait%i.png", i);
if (EDebug(EDBUG_TYPE_SESSION) > 1)
2004-12-28 15:46:49 -08:00
Eprintf("ExtInitWinCreate - child %s\n", s);
im = ThemeImageLoad(s);
2004-12-28 15:46:49 -08:00
if (im)
{
EImageRenderPixmaps(im, NULL, 0, &pmap, &mask, 0, 0);
2006-03-29 11:13:17 -08:00
EImageGetSize(im, &w, &h);
XShapeCombineMask(disp, w2, ShapeBounding, 0, 0, mask,
2004-12-28 15:46:49 -08:00
ShapeSet);
XSetWindowBackgroundPixmap(disp, w2, pmap);
EImagePixmapsFree(pmap, mask);
2004-12-28 15:46:49 -08:00
XClearWindow(disp, w2);
XQueryPointer(disp, win, &ww, &ww, &dd, &dd, &x, &y, &mm);
2006-03-29 11:13:17 -08:00
XMoveResizeWindow(disp, w2, x - w / 2, y - h / 2, w, h);
XMapWindow(disp, w2);
2006-03-29 11:13:17 -08:00
EImageFree(im);
2004-12-28 15:46:49 -08:00
}
usleep(50000);
ESync(0);
2004-12-28 15:46:49 -08:00
}
}
if (EDebug(EDBUG_TYPE_SESSION))
2004-12-28 15:46:49 -08:00
Eprintf("ExtInitWinMain exit\n");
EDisplayClose();
2004-12-28 15:46:49 -08:00
exit(0);
}
Window
ExtInitWinCreate(void)
{
Ecore_X_Window win_ex; /* Hmmm.. */
2004-12-28 15:46:49 -08:00
Window win;
Atom a;
if (EDebug(EDBUG_TYPE_SESSION))
2004-12-28 15:46:49 -08:00
Eprintf("ExtInitWinCreate\n");
a = EInternAtom("ENLIGHTENMENT_RESTART_SCREEN");
ESync(0);
2004-12-28 15:46:49 -08:00
if (fork())
{
/* Parent */
EUngrabServer();
2004-12-28 15:46:49 -08:00
for (;;)
{
if (EDebug(EDBUG_TYPE_SESSION))
2004-12-28 15:46:49 -08:00
Eprintf("ExtInitWinCreate - parent\n");
/* Hack to give the child some space. Not foolproof. */
sleep(1);
if (ecore_x_window_prop_window_get
(WinGetXwin(VROOT), a, &win_ex, 1) > 0)
2004-12-28 15:46:49 -08:00
break;
}
win = win_ex;
if (EDebug(EDBUG_TYPE_SESSION))
2004-12-28 15:46:49 -08:00
Eprintf("ExtInitWinCreate - parent - %#lx\n", win);
return win;
}
/* Child - Create the init window */
if (EDebug(EDBUG_TYPE_SESSION))
2004-12-28 15:46:49 -08:00
Eprintf("ExtInitWinCreate - child\n");
/* Clean up inherited stuff */
SignalsRestore();
EImageExit(0);
2004-12-28 15:46:49 -08:00
EDisplayDisconnect();
ExtInitWinMain();
/* We will never get here */
return None;
}
static Window init_win_ext = None;
void
ExtInitWinSet(Window win)
{
init_win_ext = win;
}
Window
ExtInitWinGet(void)
{
return init_win_ext;
}
void
ExtInitWinKill(void)
{
if (!disp || init_win_ext == None)
return;
if (EDebug(EDBUG_TYPE_SESSION))
Eprintf("Kill init window %#lx\n", init_win_ext);
XUnmapWindow(disp, init_win_ext);
init_win_ext = None;
}