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
|
2022-02-10 05:53:13 -08:00
|
|
|
* Copyright (C) 2004-2022 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.
|
|
|
|
*/
|
2015-01-15 22:25:38 -08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
2008-10-07 12:41:57 -07:00
|
|
|
#include <X11/Xutil.h>
|
2008-06-05 01:55:21 -07:00
|
|
|
#include <X11/extensions/shape.h>
|
2009-08-30 07:04:29 -07:00
|
|
|
#define USE_EIWC_WINDOW 1
|
2009-08-18 10:27:08 -07:00
|
|
|
#if USE_XRENDER
|
2009-08-30 07:04:29 -07:00
|
|
|
#define USE_EIWC_RENDER 1
|
2009-07-18 03:19:25 -07:00
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
#endif
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2015-01-15 22:25:38 -08:00
|
|
|
#include "E.h"
|
|
|
|
#include "eimage.h"
|
2018-02-12 08:08:12 -08:00
|
|
|
#include "events.h"
|
2015-01-15 22:25:38 -08:00
|
|
|
#include "xprop.h"
|
|
|
|
#include "xwin.h"
|
|
|
|
|
2009-07-18 03:19:23 -07:00
|
|
|
typedef struct {
|
2023-10-21 02:04:12 -07:00
|
|
|
EX_Cursor curs;
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
EX_Window cwin;
|
2009-07-18 03:19:23 -07:00
|
|
|
} EiwData;
|
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
typedef void (EiwLoopFunc) (EX_Window win, EImage * im, EiwData * d);
|
2009-08-30 07:04:29 -07:00
|
|
|
|
|
|
|
#if USE_EIWC_RENDER
|
2023-10-21 02:04:12 -07:00
|
|
|
static void _eiw_render_loop(EX_Window win, EImage * im, EiwData * d);
|
2009-08-30 07:04:29 -07:00
|
|
|
|
|
|
|
static EiwLoopFunc *
|
2023-10-21 02:04:12 -07:00
|
|
|
_eiw_render_init(EX_Window win __UNUSED__, EiwData *d)
|
2009-07-18 03:19:25 -07:00
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
Visual *vis;
|
2009-07-18 03:19:25 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
/* Quit if no ARGB visual.
|
|
|
|
* If we have, assume(?) a colored XRenderCreateCursor is available. */
|
|
|
|
vis = EVisualFindARGB();
|
|
|
|
if (!vis)
|
|
|
|
return NULL;
|
2009-07-18 03:19:25 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
d->curs = NoXID;
|
2009-08-30 07:04:29 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
return _eiw_render_loop;
|
2009-07-18 03:19:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-10-21 02:04:12 -07:00
|
|
|
_eiw_render_loop(EX_Window win, EImage *im, EiwData *d)
|
2009-07-18 03:19:25 -07:00
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
int w, h;
|
2009-07-18 03:19:25 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
EImageGetSize(im, &w, &h);
|
2009-07-18 03:19:25 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
if (d->curs != NoXID)
|
|
|
|
XFreeCursor(disp, d->curs);
|
|
|
|
d->curs = EImageDefineCursor(im, w / 2, h / 2);
|
2009-07-18 03:19:25 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
XDefineCursor(disp, win, d->curs);
|
2009-07-18 03:19:25 -07:00
|
|
|
}
|
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
#endif /* USE_EIWC_RENDER */
|
2009-07-18 03:19:25 -07:00
|
|
|
|
2009-08-30 07:04:29 -07:00
|
|
|
#if USE_EIWC_WINDOW
|
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
static void _eiw_window_loop(EX_Window win, EImage * im, EiwData * d);
|
2009-08-30 07:04:29 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
static EX_Cursor
|
2022-12-22 23:04:11 -08:00
|
|
|
_DefineNullCursor(EX_Window win)
|
2009-07-18 03:19:23 -07:00
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
EX_Cursor curs;
|
|
|
|
EX_Pixmap pmap, mask;
|
|
|
|
XColor cl = { };
|
2022-12-22 23:04:11 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
pmap = XCreatePixmap(disp, win, 16, 16, 1);
|
|
|
|
EXFillAreaSolid(pmap, 0, 0, 16, 16, 0);
|
|
|
|
mask = pmap;
|
2022-12-22 23:04:11 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
curs = XCreatePixmapCursor(disp, pmap, mask, &cl, &cl, 0, 0);
|
2022-12-22 23:04:11 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
XFreePixmap(disp, pmap);
|
2009-07-18 03:19:23 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
return curs;
|
2022-12-22 23:04:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static EiwLoopFunc *
|
2023-10-21 02:04:12 -07:00
|
|
|
_eiw_window_init(EX_Window win, EiwData *d)
|
2022-12-22 23:04:11 -08:00
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
d->cwin = XCreateWindow(disp, WinGetXwin(RROOT), 0, 0, 32, 32, 0,
|
|
|
|
CopyFromParent, InputOutput, CopyFromParent,
|
|
|
|
CWOverrideRedirect | CWBackingStore | CWBackPixel,
|
|
|
|
&d->attr);
|
2009-07-18 03:19:23 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
d->curs = _DefineNullCursor(d->cwin);
|
2009-07-18 03:19:23 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
XDefineCursor(disp, win, d->curs);
|
|
|
|
XDefineCursor(disp, d->cwin, d->curs);
|
2009-08-30 07:04:29 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
return _eiw_window_loop;
|
2009-07-18 03:19:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-10-21 02:04:12 -07:00
|
|
|
_eiw_window_loop(EX_Window win, EImage *im, EiwData *d)
|
2009-07-18 03:19:23 -07:00
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
EX_Pixmap pmap, mask;
|
|
|
|
Window ww;
|
|
|
|
int dd, x, y, w, h;
|
|
|
|
unsigned int mm;
|
|
|
|
|
|
|
|
EImageRenderPixmaps(im, RROOT, 0, &pmap, &mask, 0, 0);
|
|
|
|
EImageGetSize(im, &w, &h);
|
|
|
|
XShapeCombineMask(disp, d->cwin, ShapeBounding, 0, 0, mask, ShapeSet);
|
|
|
|
XSetWindowBackgroundPixmap(disp, d->cwin, pmap);
|
|
|
|
EImagePixmapsFree(pmap, mask);
|
|
|
|
XClearWindow(disp, d->cwin);
|
|
|
|
XQueryPointer(disp, win, &ww, &ww, &dd, &dd, &x, &y, &mm);
|
|
|
|
XMoveResizeWindow(disp, d->cwin, x - w / 2, y - h / 2, w, h);
|
|
|
|
XMapWindow(disp, d->cwin);
|
2009-07-18 03:19:23 -07:00
|
|
|
}
|
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
#endif /* USE_EIWC_WINDOW */
|
2009-07-18 03:19:25 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
static EX_Window
|
2004-12-28 15:46:49 -08:00
|
|
|
ExtInitWinMain(void)
|
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
int i, loop, err;
|
|
|
|
EX_Window win;
|
|
|
|
EX_Pixmap pmap;
|
|
|
|
EX_Atom a;
|
|
|
|
EiwData eiwd;
|
|
|
|
EiwLoopFunc *eiwc_loop_func;
|
|
|
|
unsigned int wclass, vmask;
|
|
|
|
|
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
|
|
|
Eprintf("%s: enter\n", __func__);
|
|
|
|
|
|
|
|
err = EDisplayOpen(NULL, -1);
|
|
|
|
if (err)
|
|
|
|
return NoXID;
|
|
|
|
|
|
|
|
EDisplaySetErrorHandlers(EventShowError, NULL);
|
|
|
|
|
|
|
|
EGrabServer();
|
|
|
|
|
|
|
|
EImageInit();
|
|
|
|
|
|
|
|
eiwd.attr.override_redirect = True;
|
|
|
|
eiwd.attr.background_pixmap = NoXID;
|
|
|
|
eiwd.attr.backing_store = NotUseful;
|
|
|
|
eiwd.attr.save_under = True;
|
|
|
|
eiwd.attr.background_pixel = 0; /* Not used */
|
|
|
|
wclass = InputOnly;
|
|
|
|
vmask = CWOverrideRedirect;
|
|
|
|
if (!Mode.wm.window)
|
|
|
|
{
|
|
|
|
pmap = ECreatePixmap(RROOT, WinGetW(RROOT), WinGetH(RROOT), 0);
|
|
|
|
EXCopyArea(WinGetXwin(RROOT), pmap, 0, 0,
|
|
|
|
WinGetW(RROOT), WinGetH(RROOT), 0, 0);
|
|
|
|
eiwd.attr.background_pixmap = pmap;
|
|
|
|
wclass = InputOutput;
|
|
|
|
vmask |= CWBackPixmap | CWBackingStore | CWSaveUnder;
|
|
|
|
}
|
|
|
|
win = XCreateWindow(disp, WinGetXwin(RROOT),
|
|
|
|
0, 0, WinGetW(RROOT), WinGetH(RROOT),
|
|
|
|
0, CopyFromParent, wclass, CopyFromParent,
|
|
|
|
vmask, &eiwd.attr);
|
|
|
|
if (!Mode.wm.window)
|
|
|
|
{
|
|
|
|
EFreePixmap(eiwd.attr.background_pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
XMapRaised(disp, win);
|
|
|
|
|
|
|
|
a = ex_atom_get("ENLIGHTENMENT_RESTART_SCREEN");
|
|
|
|
ex_window_prop_window_set(WinGetXwin(RROOT), a, &win, 1);
|
|
|
|
|
|
|
|
XSelectInput(disp, win, StructureNotifyMask);
|
|
|
|
|
|
|
|
EUngrabServer();
|
|
|
|
ESync(0);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2009-08-30 07:04:29 -07:00
|
|
|
#if USE_EIWC_WINDOW && USE_EIWC_RENDER
|
2023-10-21 02:04:12 -07:00
|
|
|
eiwc_loop_func = _eiw_render_init(win, &eiwd);
|
|
|
|
if (!eiwc_loop_func)
|
|
|
|
eiwc_loop_func = _eiw_window_init(win, &eiwd);
|
2009-08-30 07:04:29 -07:00
|
|
|
#elif USE_EIWC_RENDER
|
2023-10-21 02:04:12 -07:00
|
|
|
eiwc_loop_func = _eiw_render_init(win, &eiwd);
|
2009-08-30 07:04:29 -07:00
|
|
|
#elif USE_EIWC_WINDOW
|
2023-10-21 02:04:12 -07:00
|
|
|
eiwc_loop_func = _eiw_window_init(win, &eiwd);
|
2009-08-30 07:04:29 -07:00
|
|
|
#endif
|
2023-10-21 02:04:12 -07:00
|
|
|
if (!eiwc_loop_func)
|
|
|
|
return NoXID;
|
|
|
|
|
|
|
|
{
|
|
|
|
XWindowAttributes xwa;
|
|
|
|
char s[1024];
|
|
|
|
EImage *im;
|
|
|
|
|
|
|
|
for (i = loop = 1;; i++, loop++)
|
|
|
|
{
|
|
|
|
if (i > 12)
|
|
|
|
i = 1;
|
|
|
|
|
|
|
|
/* If we get unmapped we are done */
|
|
|
|
if (!XGetWindowAttributes(disp, win, &xwa) ||
|
|
|
|
(xwa.map_state == IsUnmapped))
|
|
|
|
{
|
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
|
|
|
Eprintf("%s: child done\n", __func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Esnprintf(s, sizeof(s), "pix/wait%i.png", i);
|
|
|
|
if (EDebug(EDBUG_TYPE_SESSION) > 1)
|
|
|
|
Eprintf("%s: child %s\n", __func__, s);
|
|
|
|
|
|
|
|
im = ThemeImageLoad(s);
|
|
|
|
if (im)
|
|
|
|
{
|
|
|
|
eiwc_loop_func(win, im, &eiwd);
|
|
|
|
EImageFree(im);
|
|
|
|
}
|
|
|
|
ESync(0);
|
|
|
|
SleepUs(50 * 1000);
|
|
|
|
|
|
|
|
/* If we still are here after 60 sec something is wrong. */
|
|
|
|
if (loop > 60000 / 50)
|
|
|
|
{
|
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
|
|
|
Eprintf("%s: child timeout\n", __func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EDisplayClose();
|
|
|
|
|
|
|
|
exit(0);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
|
2009-12-03 11:29:30 -08:00
|
|
|
EX_Window
|
2004-12-28 15:46:49 -08:00
|
|
|
ExtInitWinCreate(void)
|
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
EX_Window win_ex; /* Hmmm.. */
|
|
|
|
EX_Window win;
|
|
|
|
EX_Atom a;
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
|
|
|
Eprintf("%s\n", __func__);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
a = ex_atom_get("ENLIGHTENMENT_RESTART_SCREEN");
|
|
|
|
ex_window_prop_window_set(WinGetXwin(RROOT), a, NULL, 0);
|
|
|
|
ESync(0);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
if (fork())
|
|
|
|
{
|
|
|
|
/* Parent */
|
|
|
|
EUngrabServer();
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
|
|
|
Eprintf("%s: parent\n", __func__);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
/* Hack to give the child some space. Not foolproof. */
|
|
|
|
SleepUs(500000);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
if (ex_window_prop_window_get(WinGetXwin(RROOT), a, &win_ex, 1) > 0)
|
|
|
|
break;
|
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
win = win_ex;
|
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
|
|
|
Eprintf("%s: parent - %#x\n", __func__, win);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
return win;
|
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
/* Child - Create the init window */
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
|
|
|
Eprintf("%s: child\n", __func__);
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
/* Clean up inherited stuff */
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
SignalsRestore();
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
EImageExit(0);
|
|
|
|
EDisplayDisconnect();
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
ExtInitWinMain();
|
2004-12-28 15:46:49 -08:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
/* We will never get here */
|
|
|
|
return NoXID;
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
2005-04-23 06:35:37 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
static EX_Window init_win_ext = NoXID;
|
2005-04-23 06:35:37 -07:00
|
|
|
|
|
|
|
void
|
2009-12-03 11:29:30 -08:00
|
|
|
ExtInitWinSet(EX_Window win)
|
2005-04-23 06:35:37 -07:00
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
init_win_ext = win;
|
2005-04-23 06:35:37 -07:00
|
|
|
}
|
|
|
|
|
2009-12-03 11:29:30 -08:00
|
|
|
EX_Window
|
2005-04-23 06:35:37 -07:00
|
|
|
ExtInitWinGet(void)
|
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
return init_win_ext;
|
2005-04-23 06:35:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ExtInitWinKill(void)
|
|
|
|
{
|
2023-10-21 02:04:12 -07:00
|
|
|
if (!disp || init_win_ext == NoXID)
|
|
|
|
return;
|
2005-04-23 06:35:37 -07:00
|
|
|
|
2023-10-21 02:04:12 -07:00
|
|
|
if (EDebug(EDBUG_TYPE_SESSION))
|
|
|
|
Eprintf("%s: %#x\n", __func__, init_win_ext);
|
|
|
|
XUnmapWindow(disp, init_win_ext);
|
|
|
|
init_win_ext = NoXID;
|
2005-04-23 06:35:37 -07:00
|
|
|
}
|