~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to client/screenlocker/screenlocker.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080617134654-cl0gi4u524cv1ici
Tags: 1:1.0.9~rc3-1
* Package new upstream version
  - upstream ported the code to qt4.4 (Closes: #481974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  screen_locker.c - screen-locker, which is part of the iTALC client-software
3
 
 *
4
 
 *  iTALC/Client-software
5
 
 *  Copyright (c) 2004-2005 Tobias Doerffel <tobias@doerffel.de>
6
 
 *
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.
11
 
 *
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.
16
 
 *
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,
20
 
 *  USA.
21
 
 */
22
 
 
23
 
 
24
 
#include <stdio.h>
25
 
#include <unistd.h>
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>
31
 
 
32
 
 
33
 
 
34
 
#define AllPointerEventMask \
35
 
        (ButtonPressMask | ButtonReleaseMask | \
36
 
        EnterWindowMask | LeaveWindowMask | \
37
 
        PointerMotionMask | PointerMotionHintMask | \
38
 
        Button1MotionMask | Button2MotionMask | \
39
 
        Button3MotionMask | Button4MotionMask | \
40
 
        Button5MotionMask | ButtonMotionMask | \
41
 
        KeymapStateMask)
42
 
 
43
 
        
44
 
/* TODO: don't use X-Athena-Widgets (xaw)*/
45
 
 
46
 
int main (int argc, char **argv) {
47
 
 
48
 
        XtResource desktopBackingStoreResources[] = { { XtNbackingStore, XtCBackingStore, XtRBackingStore, sizeof(int), 0, XtRImmediate, (XtPointer) Always, }, };
49
 
 
50
 
        Display * display;
51
 
        Visual * vis;
52
 
 
53
 
        XSetWindowAttributes attr;
54
 
        unsigned long valuemask;
55
 
 
56
 
        Pixmap src, msk;
57
 
        XColor fg, bg;
58
 
        int blackColor;
59
 
        GC gc;
60
 
 
61
 
        Widget toplevel;
62
 
        Dimension displayWidth, displayHeight;
63
 
 
64
 
        Cursor blankcursor;
65
 
 
66
 
        Widget form, viewport, desktop;
67
 
        Window desktop_win;
68
 
 
69
 
        char srcBits[] = { 0,0,0,0,0 };
70
 
        char mskBits[] = { 0,0,0,0,0 };
71
 
 
72
 
 
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);
76
 
 
77
 
        display = XtDisplay(toplevel);
78
 
 
79
 
        vis = DefaultVisual(display, DefaultScreen(display));
80
 
 
81
 
        displayWidth = WidthOfScreen(DefaultScreenOfDisplay(display));
82
 
        displayHeight = HeightOfScreen(DefaultScreenOfDisplay(display));
83
 
        
84
 
 
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);
87
 
 
88
 
 
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);
92
 
 
93
 
        XtVaSetValues(desktop, XtNwidth, displayWidth, XtNheight, displayHeight, NULL);
94
 
 
95
 
        /* "Realize" all the widgets, i.e. actually create and map their X windows */
96
 
        XtRealizeWidget(toplevel);
97
 
 
98
 
 
99
 
 
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);
105
 
 
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);
114
 
 
115
 
        /* Now we can set "toplevel" to its proper size. */
116
 
        XtResizeWidget(toplevel, displayWidth, displayHeight, 0);
117
 
 
118
 
 
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);
123
 
 
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);
127
 
 
128
 
 
129
 
 
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);
137
 
 
138
 
        XtVaGetApplicationResources(desktop, (XtPointer)&attr.backing_store, desktopBackingStoreResources, 1, NULL);
139
 
        valuemask = CWBackingStore;
140
 
 
141
 
        attr.cursor = blankcursor;
142
 
        valuemask |= CWCursor;
143
 
 
144
 
        XChangeWindowAttributes(display, desktop_win, valuemask, &attr);
145
 
  
146
 
        /* Try to get the input focus. */
147
 
        XSetInputFocus(display, DefaultRootWindow(display), RevertToPointerRoot, CurrentTime);
148
 
 
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");
153
 
        }
154
 
 
155
 
        while (1) {
156
 
                /* sleep a little bit - only for better task-scheduling... */
157
 
                sleep (5);
158
 
        }
159
 
 
160
 
        return (0);
161
 
 
162
 
}