Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbejy@wpi.edu>
[wine/multimedia.git] / windows / x11drv / monitor.c
blobdebec810d0a3021f4e1259ec535fca52791ab53d
1 /*
2 * X11 monitor driver
4 * Copyright 1998 Patrik Stridvall
6 */
8 #include "config.h"
10 #ifndef X_DISPLAY_MISSING
12 #include <stdlib.h>
13 #include <X11/cursorfont.h>
14 #include "ts_xlib.h"
15 #include "ts_xutil.h"
17 #include "debug.h"
18 #include "heap.h"
19 #include "monitor.h"
20 #include "options.h"
21 #include "windef.h"
22 #include "x11drv.h"
24 /**********************************************************************/
26 extern Display *display;
28 /***********************************************************************
29 * X11DRV_MONITOR_GetXScreen
31 * Return the X screen associated to the MONITOR.
33 Screen *X11DRV_MONITOR_GetXScreen(MONITOR *pMonitor)
35 X11DRV_MONITOR_DATA *pX11Monitor =
36 (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
38 return pX11Monitor->screen;
41 /***********************************************************************
42 * X11DRV_MONITOR_GetXRootWindow
44 * Return the X screen associated to the MONITOR.
46 Window X11DRV_MONITOR_GetXRootWindow(MONITOR *pMonitor)
48 X11DRV_MONITOR_DATA *pX11Monitor =
49 (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
51 return pX11Monitor->rootWindow;
54 /***********************************************************************
55 * X11DRV_MONITOR_CreateDesktop
56 * FIXME
57 * The desktop should create created in X11DRV_DESKTOP_Initialize
58 * instead but it can't be yet because some code depends on that
59 * the desktop always exists.
62 static void X11DRV_MONITOR_CreateDesktop(MONITOR *pMonitor)
64 X11DRV_MONITOR_DATA *pX11Monitor =
65 (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
67 int x, y, flags;
68 unsigned int width = 640, height = 480; /* Default size = 640x480 */
69 char *name = "Wine desktop";
70 XSizeHints *size_hints;
71 XWMHints *wm_hints;
72 XClassHint *class_hints;
73 XSetWindowAttributes win_attr;
74 XTextProperty window_name;
75 Atom XA_WM_DELETE_WINDOW;
77 flags = TSXParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
78 pX11Monitor->width = width;
79 pX11Monitor->height = height;
81 /* Create window */
83 win_attr.background_pixel = BlackPixel(display, 0);
84 win_attr.event_mask =
85 ExposureMask | KeyPressMask | KeyReleaseMask |
86 PointerMotionMask | ButtonPressMask |
87 ButtonReleaseMask | EnterWindowMask;
88 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
90 pX11Monitor->rootWindow =
91 TSXCreateWindow( display,
92 DefaultRootWindow(display),
93 x, y, width, height, 0,
94 CopyFromParent, InputOutput, CopyFromParent,
95 CWBackPixel | CWEventMask | CWCursor, &win_attr);
97 /* Set window manager properties */
99 size_hints = TSXAllocSizeHints();
100 wm_hints = TSXAllocWMHints();
101 class_hints = TSXAllocClassHint();
102 if (!size_hints || !wm_hints || !class_hints)
104 MSG("Not enough memory for window manager hints.\n" );
105 exit(1);
107 size_hints->min_width = size_hints->max_width = width;
108 size_hints->min_height = size_hints->max_height = height;
109 size_hints->flags = PMinSize | PMaxSize;
110 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
111 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
112 else size_hints->flags |= PSize;
114 wm_hints->flags = InputHint | StateHint;
115 wm_hints->input = True;
116 wm_hints->initial_state = NormalState;
117 class_hints->res_name = Options.argv[0]; /* FIXME: Options.argv0 insteed? */
118 class_hints->res_class = "Wine";
120 TSXStringListToTextProperty( &name, 1, &window_name );
121 TSXSetWMProperties( display, pX11Monitor->rootWindow, &window_name, &window_name,
122 Options.argv, *Options.argc, size_hints, wm_hints, class_hints );
123 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
124 TSXSetWMProtocols( display, pX11Monitor->rootWindow, &XA_WM_DELETE_WINDOW, 1 );
125 TSXFree( size_hints );
126 TSXFree( wm_hints );
127 TSXFree( class_hints );
129 /* Map window */
131 TSXMapWindow( display, pX11Monitor->rootWindow );
134 /***********************************************************************
135 * X11DRV_MONITOR_Initialize
137 void X11DRV_MONITOR_Initialize(MONITOR *pMonitor)
139 X11DRV_MONITOR_DATA *pX11Monitor = (X11DRV_MONITOR_DATA *)
140 HeapAlloc(SystemHeap, 0, sizeof(X11DRV_MONITOR_DATA));
142 int depth_count, i;
143 int *depth_list;
145 pMonitor->pDriverData = pX11Monitor;
147 pX11Monitor->screen = DefaultScreenOfDisplay( display );
149 pX11Monitor->width = WidthOfScreen( pX11Monitor->screen );
150 pX11Monitor->height = HeightOfScreen( pX11Monitor->screen );
152 pX11Monitor->depth = Options.screenDepth;
153 if (pX11Monitor->depth) /* -depth option specified */
155 depth_list = TSXListDepths(display, DefaultScreen(display), &depth_count);
156 for (i = 0; i < depth_count; i++)
157 if (depth_list[i] == pX11Monitor->depth) break;
158 TSXFree( depth_list );
159 if (i >= depth_count)
161 MSG( "%s: Depth %d not supported on this screen.\n",
162 Options.programName, pX11Monitor->depth );
163 exit(1);
166 else
167 pX11Monitor->depth = DefaultDepthOfScreen( pX11Monitor->screen );
169 if (Options.synchronous) TSXSynchronize( display, True );
171 if (Options.desktopGeometry)
172 X11DRV_MONITOR_CreateDesktop(pMonitor);
173 else
174 pX11Monitor->rootWindow =
175 DefaultRootWindow( display );
178 /***********************************************************************
179 * X11DRV_MONITOR_Finalize
181 void X11DRV_MONITOR_Finalize(MONITOR *pMonitor)
183 HeapFree(SystemHeap, 0, pMonitor->pDriverData);
186 /***********************************************************************
187 * X11DRV_MONITOR_IsSingleWindow
189 BOOL X11DRV_MONITOR_IsSingleWindow(MONITOR *pMonitor)
191 X11DRV_MONITOR_DATA *pX11Monitor =
192 (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
194 return (pX11Monitor->rootWindow != DefaultRootWindow(display));
197 /***********************************************************************
198 * X11DRV_MONITOR_GetWidth
200 * Return the width of the monitor
202 int X11DRV_MONITOR_GetWidth(MONITOR *pMonitor)
204 X11DRV_MONITOR_DATA *pX11Monitor =
205 (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
207 return pX11Monitor->width;
210 /***********************************************************************
211 * X11DRV_MONITOR_GetHeight
213 * Return the height of the monitor
215 int X11DRV_MONITOR_GetHeight(MONITOR *pMonitor)
217 X11DRV_MONITOR_DATA *pX11Monitor =
218 (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
220 return pX11Monitor->height;
223 /***********************************************************************
224 * X11DRV_MONITOR_GetDepth
226 * Return the depth of the monitor
228 int X11DRV_MONITOR_GetDepth(MONITOR *pMonitor)
230 X11DRV_MONITOR_DATA *pX11Monitor =
231 (X11DRV_MONITOR_DATA *) pMonitor->pDriverData;
233 return pX11Monitor->depth;
236 /***********************************************************************
237 * X11DRV_MONITOR_GetScreenSaveActive
239 * Returns the active status of the screen saver
241 BOOL X11DRV_MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
243 int timeout, temp;
244 TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
245 return timeout!=NULL;
248 /***********************************************************************
249 * X11DRV_MONITOR_SetScreenSaveActive
251 * Activate/Deactivate the screen saver
253 void X11DRV_MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
255 if(bActivate)
256 TSXActivateScreenSaver(display);
257 else
258 TSXResetScreenSaver(display);
261 /***********************************************************************
262 * X11DRV_MONITOR_GetScreenSaveTimeout
264 * Return the screen saver timeout
266 int X11DRV_MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
268 int timeout, temp;
269 TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
270 return timeout;
273 /***********************************************************************
274 * X11DRV_MONITOR_SetScreenSaveTimeout
276 * Set the screen saver timeout
278 void X11DRV_MONITOR_SetScreenSaveTimeout(
279 MONITOR *pMonitor, int nTimeout)
281 TSXSetScreenSaver(display, nTimeout, 60,
282 DefaultBlanking, DefaultExposures);
285 #endif /* X_DISPLAY_MISSING */