2
* screen_locker.c - screen-locker, which is part of the iTALC client-software
4
* iTALC/Client-software
5
* Copyright (c) 2004-2005 Tobias Doerffel <tobias@doerffel.de>
7
* This is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this software; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26
#include <X11/StringDefs.h>
27
#include <X11/IntrinsicP.h>
28
#include <X11/Shell.h>
29
#include <X11/Xaw/Viewport.h>
30
#include <X11/Xmu/Converters.h>
34
#define AllPointerEventMask \
35
(ButtonPressMask | ButtonReleaseMask | \
36
EnterWindowMask | LeaveWindowMask | \
37
PointerMotionMask | PointerMotionHintMask | \
38
Button1MotionMask | Button2MotionMask | \
39
Button3MotionMask | Button4MotionMask | \
40
Button5MotionMask | ButtonMotionMask | \
44
/* TODO: don't use X-Athena-Widgets (xaw)*/
46
int main (int argc, char **argv) {
48
XtResource desktopBackingStoreResources[] = { { XtNbackingStore, XtCBackingStore, XtRBackingStore, sizeof(int), 0, XtRImmediate, (XtPointer) Always, }, };
53
XSetWindowAttributes attr;
54
unsigned long valuemask;
62
Dimension displayWidth, displayHeight;
66
Widget form, viewport, desktop;
69
char srcBits[] = { 0,0,0,0,0 };
70
char mskBits[] = { 0,0,0,0,0 };
73
/* Call the main Xt initialisation function. It parses command-line options, generating appropriate resource specs, and makes a
74
* connection to the X display. */
75
toplevel = XtVaAppInitialize(NULL, "ScreenLocker", NULL, 0, &argc, argv, NULL, XtNborderWidth, 0, NULL);
77
display = XtDisplay(toplevel);
79
vis = DefaultVisual(display, DefaultScreen(display));
81
displayWidth = WidthOfScreen(DefaultScreenOfDisplay(display));
82
displayHeight = HeightOfScreen(DefaultScreenOfDisplay(display));
85
/* full screen - set position to 0,0, but defer size calculation until widgets are realized */
86
XtVaSetValues(toplevel, XtNoverrideRedirect, True, XtNgeometry, "+0+0", NULL);
89
form = XtVaCreateManagedWidget("form", formWidgetClass, toplevel, XtNborderWidth, 0, XtNdefaultDistance, 0, NULL);
90
viewport = XtVaCreateManagedWidget("viewport", viewportWidgetClass, form, XtNborderWidth, 0, NULL);
91
desktop = XtVaCreateManagedWidget("desktop", coreWidgetClass, viewport, XtNborderWidth, 0, NULL);
93
XtVaSetValues(desktop, XtNwidth, displayWidth, XtNheight, displayHeight, NULL);
95
/* "Realize" all the widgets, i.e. actually create and map their X windows */
96
XtRealizeWidget(toplevel);
100
/* We want to stop the window manager from managing our toplevel window. This is not really a nice thing to do, so may not work
101
* properly with every window manager. We do this simply by setting overrideRedirect and reparenting our window to the root.
102
* The window manager will get a ReparentNotify and hopefully clean up its frame window. */
103
XtVaSetValues(toplevel, XtNoverrideRedirect, True, NULL);
104
XReparentWindow(display, XtWindow(toplevel), DefaultRootWindow(display), 0, 0);
106
/* Now we want to fix the size of "viewport". We shouldn't just change it directly.
107
* Instead we set "toplevel" to the required size (which should propagate through "form" to "viewport").
108
* Then we remove "viewport" from being managed by "form", change its resources to position it and make sure that "form" won't
109
* attempt to resize it, then ask "form" to manage it again. */
110
XtResizeWidget(toplevel, displayWidth, displayHeight, 0);
111
XtUnmanageChild(viewport);
112
XtVaSetValues(viewport, XtNhorizDistance, 0, XtNvertDistance, 0, XtNleft, XtChainLeft, XtNright, XtChainLeft, XtNtop, XtChainTop, XtNbottom, XtChainTop, NULL);
113
XtManageChild(viewport);
115
/* Now we can set "toplevel" to its proper size. */
116
XtResizeWidget(toplevel, displayWidth, displayHeight, 0);
119
/*image = XCreateImage(display, vis, 32, ZPixmap, 0, NULL, 2000, 2000, BitmapPad(display), 0);*/
120
blackColor = BlackPixel(display, DefaultScreen(display));
121
desktop_win = XtWindow(desktop);
122
gc = XCreateGC(display, desktop_win, 0, NULL);
124
/* Tell the GC we draw using the black color*/
125
XSetForeground(display, gc, blackColor);
126
XFillRectangle(display, desktop_win, gc, 0, 0, displayWidth, displayHeight);
130
src = XCreateBitmapFromData(display, DefaultRootWindow(display), srcBits, 5, 5);
131
msk = XCreateBitmapFromData(display, DefaultRootWindow(display), mskBits, 5, 5);
132
XAllocNamedColor(display, DefaultColormap(display,DefaultScreen(display)), "black", &fg, &fg);
133
XAllocNamedColor(display, DefaultColormap(display,DefaultScreen(display)), "white", &bg, &bg);
134
blankcursor = XCreatePixmapCursor(display, src, msk, &fg, &bg, 2, 2);
135
XFreePixmap(display, src);
136
XFreePixmap(display, msk);
138
XtVaGetApplicationResources(desktop, (XtPointer)&attr.backing_store, desktopBackingStoreResources, 1, NULL);
139
valuemask = CWBackingStore;
141
attr.cursor = blankcursor;
142
valuemask |= CWCursor;
144
XChangeWindowAttributes(display, desktop_win, valuemask, &attr);
146
/* Try to get the input focus. */
147
XSetInputFocus(display, DefaultRootWindow(display), RevertToPointerRoot, CurrentTime);
149
/* now grab keyboard and mouse */
150
if (XtGrabKeyboard(desktop, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess ||
151
XtGrabPointer(desktop, True, (unsigned int) AllPointerEventMask, GrabModeAsync, GrabModeAsync, None, blankcursor, CurrentTime) != GrabSuccess) {
152
printf ("Could not grab keyboard and mouse.\n");
156
/* sleep a little bit - only for better task-scheduling... */