A few simplifications and optimizations in the x11 driver.
[wine] / windows / x11drv / monitor.c
1 /*
2  * X11 monitor driver
3  *
4  * Copyright 1998 Patrik Stridvall
5  *
6  */
7
8 #include "config.h"
9
10 #ifndef X_DISPLAY_MISSING
11
12 #include <stdlib.h>
13 #include <X11/cursorfont.h>
14 #include "ts_xlib.h"
15 #include "ts_xutil.h"
16
17 #include "debugtools.h"
18 #include "heap.h"
19 #include "monitor.h"
20 #include "options.h"
21 #include "windef.h"
22 #include "x11drv.h"
23
24 /***********************************************************************
25  *              X11DRV_MONITOR_CreateDesktop
26  * FIXME 
27  *   The desktop should create created in X11DRV_DESKTOP_Initialize
28  *   instead but it can't be yet because some code depends on that
29  *   the desktop always exists.
30  *
31  */
32 static void X11DRV_MONITOR_CreateDesktop(MONITOR *pMonitor)
33 {
34   X11DRV_MONITOR_DATA *pX11Monitor =
35     (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
36
37   int x = 0, y = 0, flags;
38   unsigned int width = 640, height = 480;  /* Default size = 640x480 */
39   char *name = "Wine desktop";
40   XSizeHints *size_hints;
41   XWMHints   *wm_hints;
42   XClassHint *class_hints;
43   XSetWindowAttributes win_attr;
44   XTextProperty window_name;
45   Atom XA_WM_DELETE_WINDOW;
46
47   flags = TSXParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
48   pX11Monitor->width  = width;
49   pX11Monitor->height = height;
50
51   /* Create window */
52   
53   win_attr.background_pixel = BlackPixel(display, 0);
54   win_attr.event_mask = 
55     ExposureMask | KeyPressMask | KeyReleaseMask |
56     PointerMotionMask | ButtonPressMask |
57     ButtonReleaseMask | EnterWindowMask;
58   win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
59
60   root_window = TSXCreateWindow( display, 
61                      DefaultRootWindow(display),
62                      x, y, width, height, 0,
63                      CopyFromParent, InputOutput, CopyFromParent,
64                      CWBackPixel | CWEventMask | CWCursor, &win_attr);
65   
66   /* Set window manager properties */
67
68   size_hints  = TSXAllocSizeHints();
69   wm_hints    = TSXAllocWMHints();
70   class_hints = TSXAllocClassHint();
71   if (!size_hints || !wm_hints || !class_hints)
72     {
73       MESSAGE("Not enough memory for window manager hints.\n" );
74       exit(1);
75     }
76   size_hints->min_width = size_hints->max_width = width;
77   size_hints->min_height = size_hints->max_height = height;
78   size_hints->flags = PMinSize | PMaxSize;
79   if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
80   if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
81   else size_hints->flags |= PSize;
82
83   wm_hints->flags = InputHint | StateHint;
84   wm_hints->input = True;
85   wm_hints->initial_state = NormalState;
86   class_hints->res_name = (char *)argv0;
87   class_hints->res_class = "Wine";
88
89   TSXStringListToTextProperty( &name, 1, &window_name );
90   TSXSetWMProperties( display, root_window, &window_name, &window_name,
91                       Options.argv, Options.argc, size_hints, wm_hints, class_hints );
92   XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
93   TSXSetWMProtocols( display, root_window, &XA_WM_DELETE_WINDOW, 1 );
94   TSXFree( size_hints );
95   TSXFree( wm_hints );
96   TSXFree( class_hints );
97
98   /* Map window */
99
100   TSXMapWindow( display, root_window );
101 }
102
103 /***********************************************************************
104  *              X11DRV_MONITOR_Initialize
105  */
106 void X11DRV_MONITOR_Initialize(MONITOR *pMonitor)
107 {
108   X11DRV_MONITOR_DATA *pX11Monitor = (X11DRV_MONITOR_DATA *) 
109     HeapAlloc(SystemHeap, 0, sizeof(X11DRV_MONITOR_DATA));
110
111   pMonitor->pDriverData = pX11Monitor;
112
113   pX11Monitor->width   = WidthOfScreen( screen );
114   pX11Monitor->height  = HeightOfScreen( screen );
115
116   if (Options.desktopGeometry) X11DRV_MONITOR_CreateDesktop(pMonitor);
117 }
118
119 /***********************************************************************
120  *              X11DRV_MONITOR_Finalize
121  */
122 void X11DRV_MONITOR_Finalize(MONITOR *pMonitor)
123 {
124   HeapFree(SystemHeap, 0, pMonitor->pDriverData);
125 }
126
127 /***********************************************************************
128  *              X11DRV_MONITOR_IsSingleWindow
129  */
130 BOOL X11DRV_MONITOR_IsSingleWindow(MONITOR *pMonitor)
131 {
132   return (root_window != DefaultRootWindow(display));
133 }
134
135 /***********************************************************************
136  *              X11DRV_MONITOR_GetWidth
137  *
138  * Return the width of the monitor
139  */
140 int X11DRV_MONITOR_GetWidth(MONITOR *pMonitor)
141 {
142   X11DRV_MONITOR_DATA *pX11Monitor =
143     (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
144
145   return pX11Monitor->width;
146 }
147
148 /***********************************************************************
149  *              X11DRV_MONITOR_GetHeight
150  *
151  * Return the height of the monitor
152  */
153 int X11DRV_MONITOR_GetHeight(MONITOR *pMonitor)
154 {
155   X11DRV_MONITOR_DATA *pX11Monitor =
156     (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
157
158   return pX11Monitor->height;
159 }
160
161 /***********************************************************************
162  *              X11DRV_MONITOR_GetDepth
163  *
164  * Return the depth of the monitor
165  */
166 int X11DRV_MONITOR_GetDepth(MONITOR *pMonitor)
167 {
168     return screen_depth;
169 }
170
171 /***********************************************************************
172  *              X11DRV_MONITOR_GetScreenSaveActive
173  *
174  * Returns the active status of the screen saver
175  */
176 BOOL X11DRV_MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
177 {
178   int timeout, temp;
179   TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
180   return timeout!=NULL;
181 }
182
183 /***********************************************************************
184  *              X11DRV_MONITOR_SetScreenSaveActive
185  *
186  * Activate/Deactivate the screen saver
187  */
188 void X11DRV_MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
189 {
190   if(bActivate)
191     TSXActivateScreenSaver(display);
192   else
193     TSXResetScreenSaver(display);
194 }
195
196 /***********************************************************************
197  *              X11DRV_MONITOR_GetScreenSaveTimeout
198  *
199  * Return the screen saver timeout
200  */
201 int X11DRV_MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
202 {
203   int timeout, temp;
204   TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
205   return timeout;
206 }
207
208 /***********************************************************************
209  *              X11DRV_MONITOR_SetScreenSaveTimeout
210  *
211  * Set the screen saver timeout
212  */
213 void X11DRV_MONITOR_SetScreenSaveTimeout(
214   MONITOR *pMonitor, int nTimeout)
215 {
216   TSXSetScreenSaver(display, nTimeout, 60, 
217                     DefaultBlanking, DefaultExposures);
218 }
219
220 #endif /* X_DISPLAY_MISSING */