2001-05-16 21:52:29 +02:00
|
|
|
/*
|
|
|
|
* X11DRV desktop window handling
|
|
|
|
*
|
|
|
|
* Copyright 2001 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-05-16 21:52:29 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <X11/cursorfont.h>
|
2003-11-21 22:50:59 +01:00
|
|
|
#include <X11/Xlib.h>
|
2001-05-16 21:52:29 +02:00
|
|
|
|
2001-07-26 22:12:22 +02:00
|
|
|
#include "wine/winuser16.h"
|
2001-05-16 21:52:29 +02:00
|
|
|
#include "win.h"
|
2003-09-16 22:24:29 +02:00
|
|
|
#include "ddrawi.h"
|
2001-05-16 21:52:29 +02:00
|
|
|
#include "x11drv.h"
|
2003-09-16 22:24:29 +02:00
|
|
|
#include "x11ddraw.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-05-16 21:52:29 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
|
2001-05-16 21:52:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* desktop window procedure */
|
|
|
|
static LRESULT WINAPI desktop_winproc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
|
|
|
switch(message)
|
|
|
|
{
|
2003-04-19 23:27:19 +02:00
|
|
|
case WM_NCCREATE:
|
|
|
|
SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
|
|
|
|
SetDeskWallPaper( (LPSTR)-1 );
|
|
|
|
return TRUE;
|
|
|
|
|
2001-05-16 21:52:29 +02:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
PaintDesktop( (HDC)wParam );
|
2005-01-11 16:15:11 +01:00
|
|
|
return TRUE;
|
2001-05-16 21:52:29 +02:00
|
|
|
|
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
if ((wParam & 0xfff0) == SC_CLOSE) ExitWindows( 0, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SETCURSOR:
|
2003-09-10 05:56:47 +02:00
|
|
|
return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)IDC_ARROW ) );
|
2001-05-16 21:52:29 +02:00
|
|
|
|
|
|
|
case WM_NCHITTEST:
|
|
|
|
return HTCLIENT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* desktop window manager thread */
|
|
|
|
static DWORD CALLBACK desktop_thread( LPVOID driver_data )
|
|
|
|
{
|
|
|
|
Display *display;
|
|
|
|
MSG msg;
|
|
|
|
HWND hwnd;
|
|
|
|
WND *win;
|
2003-11-20 05:24:18 +01:00
|
|
|
Atom atom = x11drv_atom(WM_DELETE_WINDOW);
|
2001-05-16 21:52:29 +02:00
|
|
|
|
|
|
|
NtCurrentTeb()->driver_data = driver_data;
|
|
|
|
display = thread_display();
|
|
|
|
hwnd = GetDesktopWindow();
|
|
|
|
|
|
|
|
/* patch the desktop window queue to point to our queue */
|
2001-10-15 19:56:45 +02:00
|
|
|
win = WIN_GetPtr( hwnd );
|
2001-08-28 20:44:52 +02:00
|
|
|
win->tid = GetCurrentThreadId();
|
2001-06-04 23:55:17 +02:00
|
|
|
X11DRV_register_window( display, hwnd, win->pDriverData );
|
2001-10-15 19:56:45 +02:00
|
|
|
WIN_ReleasePtr( win );
|
2001-05-16 21:52:29 +02:00
|
|
|
|
2004-09-22 21:14:08 +02:00
|
|
|
SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)desktop_winproc );
|
2001-06-04 23:55:17 +02:00
|
|
|
wine_tsx11_lock();
|
2003-11-20 05:24:18 +01:00
|
|
|
XChangeProperty ( display, root_window, x11drv_atom(WM_PROTOCOLS),
|
|
|
|
XA_ATOM, 32, PropModeReplace, (char *)&atom, 1 );
|
2001-06-04 23:55:17 +02:00
|
|
|
XMapWindow( display, root_window );
|
|
|
|
wine_tsx11_unlock();
|
2001-05-16 21:52:29 +02:00
|
|
|
|
2003-04-19 23:27:19 +02:00
|
|
|
SendMessageW( hwnd, WM_NCCREATE, 0, 0 /* should be CREATESTRUCT */ );
|
|
|
|
|
2001-05-16 21:52:29 +02:00
|
|
|
while (GetMessageW( &msg, hwnd, 0, 0 )) DispatchMessageW( &msg );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_create_desktop_thread
|
|
|
|
*
|
|
|
|
* Create the thread that manages the desktop window
|
|
|
|
*/
|
|
|
|
void X11DRV_create_desktop_thread(void)
|
|
|
|
{
|
2003-01-28 01:34:07 +01:00
|
|
|
HANDLE handle = CreateThread( NULL, 0, desktop_thread, NtCurrentTeb()->driver_data,
|
|
|
|
0, &desktop_tid );
|
2001-05-16 21:52:29 +02:00
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
MESSAGE( "Could not create desktop thread\n" );
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
/* we transferred our driver data to the new thread */
|
|
|
|
NtCurrentTeb()->driver_data = NULL;
|
|
|
|
CloseHandle( handle );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-16 22:24:29 +02:00
|
|
|
/* data for resolution changing */
|
|
|
|
static LPDDHALMODEINFO dd_modes;
|
2003-10-16 02:21:42 +02:00
|
|
|
static unsigned int dd_mode_count;
|
2003-09-16 22:24:29 +02:00
|
|
|
|
|
|
|
static unsigned int max_width;
|
|
|
|
static unsigned int max_height;
|
|
|
|
|
2003-09-30 02:31:42 +02:00
|
|
|
static const unsigned int widths[] = {320, 512, 640, 800, 1024, 1152, 1280, 1600};
|
|
|
|
static const unsigned int heights[] = {200, 384, 480, 600, 768, 864, 1024, 1200};
|
2003-10-16 02:21:42 +02:00
|
|
|
#define NUM_DESKTOP_MODES (8)
|
2003-09-16 22:24:29 +02:00
|
|
|
|
|
|
|
/* create the mode structures */
|
|
|
|
static void make_modes(void)
|
|
|
|
{
|
2003-10-16 02:21:42 +02:00
|
|
|
int i;
|
2003-09-30 02:31:42 +02:00
|
|
|
/* original specified desktop size */
|
2003-10-16 02:21:42 +02:00
|
|
|
X11DRV_Settings_AddOneMode(screen_width, screen_height, 0, 0);
|
|
|
|
for (i=0; i<NUM_DESKTOP_MODES; i++)
|
2003-09-16 22:24:29 +02:00
|
|
|
{
|
2003-09-30 02:31:42 +02:00
|
|
|
if ( (widths[i] <= max_width) && (heights[i] <= max_height) )
|
|
|
|
{
|
|
|
|
if ( ( (widths[i] != max_width) || (heights[i] != max_height) ) &&
|
|
|
|
( (widths[i] != screen_width) || (heights[i] != screen_height) ) )
|
|
|
|
{
|
|
|
|
/* only add them if they are smaller than the root window and unique */
|
2003-10-16 02:21:42 +02:00
|
|
|
X11DRV_Settings_AddOneMode(widths[i], heights[i], 0, 0);
|
2003-09-30 02:31:42 +02:00
|
|
|
}
|
|
|
|
}
|
2003-09-16 22:24:29 +02:00
|
|
|
}
|
2003-09-30 02:31:42 +02:00
|
|
|
if ((max_width != screen_width) && (max_height != screen_height))
|
2003-09-16 22:24:29 +02:00
|
|
|
{
|
2003-09-30 02:31:42 +02:00
|
|
|
/* root window size (if different from desktop window) */
|
2003-10-16 02:21:42 +02:00
|
|
|
X11DRV_Settings_AddOneMode(max_width, max_height, 0, 0);
|
2003-09-16 22:24:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_resize_desktop
|
|
|
|
*
|
|
|
|
* Reset the desktop window size and WM hints
|
|
|
|
*/
|
|
|
|
int X11DRV_resize_desktop( unsigned int width, unsigned int height )
|
|
|
|
{
|
|
|
|
XSizeHints *size_hints;
|
|
|
|
Display *display = thread_display();
|
|
|
|
Window w = root_window;
|
|
|
|
/* set up */
|
|
|
|
wine_tsx11_lock();
|
|
|
|
size_hints = XAllocSizeHints();
|
|
|
|
if (!size_hints)
|
|
|
|
{
|
|
|
|
ERR("Not enough memory for window manager hints.\n" );
|
2003-09-26 06:29:57 +02:00
|
|
|
wine_tsx11_unlock();
|
2003-09-16 22:24:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
size_hints->min_width = size_hints->max_width = width;
|
|
|
|
size_hints->min_height = size_hints->max_height = height;
|
|
|
|
size_hints->flags = PMinSize | PMaxSize | PSize;
|
|
|
|
|
|
|
|
/* do the work */
|
|
|
|
XSetWMNormalHints( display, w, size_hints );
|
|
|
|
XResizeWindow( display, w, width, height );
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
XFree( size_hints );
|
|
|
|
XFlush( display );
|
|
|
|
wine_tsx11_unlock();
|
2004-02-13 04:58:21 +01:00
|
|
|
X11DRV_handle_desktop_resize( width, height );
|
2003-09-16 22:24:29 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
int X11DRV_desktop_GetCurrentMode(void)
|
|
|
|
{
|
2004-08-12 01:45:34 +02:00
|
|
|
unsigned int i;
|
2003-10-16 02:21:42 +02:00
|
|
|
DWORD dwBpp = screen_depth;
|
|
|
|
if (dwBpp == 24) dwBpp = 32;
|
|
|
|
for (i=0; i<dd_mode_count; i++)
|
|
|
|
{
|
|
|
|
if ( (screen_width == dd_modes[i].dwWidth) &&
|
|
|
|
(screen_height == dd_modes[i].dwHeight) &&
|
|
|
|
(dwBpp == dd_modes[i].dwBPP))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
ERR("In unknown mode, returning default\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11DRV_desktop_SetCurrentMode(int mode)
|
|
|
|
{
|
|
|
|
DWORD dwBpp = screen_depth;
|
|
|
|
if (dwBpp == 24) dwBpp = 32;
|
|
|
|
TRACE("Resizing Wine desktop window to %ldx%ld\n", dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
|
|
|
|
X11DRV_resize_desktop(dd_modes[mode].dwWidth, dd_modes[mode].dwHeight);
|
|
|
|
if (dwBpp != dd_modes[mode].dwBPP)
|
|
|
|
{
|
|
|
|
FIXME("Cannot change screen BPP from %ld to %ld\n", dwBpp, dd_modes[mode].dwBPP);
|
|
|
|
}
|
|
|
|
}
|
2003-09-16 22:24:29 +02:00
|
|
|
|
2001-05-16 21:52:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_create_desktop
|
|
|
|
*
|
|
|
|
* Create the X11 desktop window for the desktop mode.
|
|
|
|
*/
|
|
|
|
Window X11DRV_create_desktop( XVisualInfo *desktop_vi, const char *geometry )
|
|
|
|
{
|
|
|
|
int x = 0, y = 0, flags;
|
|
|
|
unsigned int width = 640, height = 480; /* Default size = 640x480 */
|
2002-06-13 21:11:21 +02:00
|
|
|
char *name = GetCommandLineA();
|
2001-05-16 21:52:29 +02:00
|
|
|
XSizeHints *size_hints;
|
|
|
|
XWMHints *wm_hints;
|
|
|
|
XClassHint *class_hints;
|
|
|
|
XSetWindowAttributes win_attr;
|
|
|
|
XTextProperty window_name;
|
|
|
|
Window win;
|
|
|
|
Display *display = thread_display();
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
flags = XParseGeometry( geometry, &x, &y, &width, &height );
|
2003-09-16 22:24:29 +02:00
|
|
|
max_width = screen_width;
|
|
|
|
max_height = screen_height;
|
2001-05-16 21:52:29 +02:00
|
|
|
screen_width = width;
|
|
|
|
screen_height = height;
|
|
|
|
|
|
|
|
/* Create window */
|
|
|
|
win_attr.background_pixel = BlackPixel(display, 0);
|
|
|
|
win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
|
|
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
|
|
|
|
win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
|
|
|
|
|
|
|
|
if (desktop_vi)
|
|
|
|
win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
|
|
|
|
visual, AllocNone );
|
|
|
|
else
|
|
|
|
win_attr.colormap = None;
|
|
|
|
|
|
|
|
win = XCreateWindow( display, DefaultRootWindow(display),
|
|
|
|
x, y, width, height, 0, screen_depth, InputOutput, visual,
|
|
|
|
CWBackPixel | CWEventMask | CWCursor | CWColormap, &win_attr );
|
|
|
|
|
|
|
|
/* Set window manager properties */
|
|
|
|
size_hints = XAllocSizeHints();
|
|
|
|
wm_hints = XAllocWMHints();
|
|
|
|
class_hints = XAllocClassHint();
|
|
|
|
if (!size_hints || !wm_hints || !class_hints)
|
|
|
|
{
|
|
|
|
MESSAGE("Not enough memory for window manager hints.\n" );
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
size_hints->min_width = size_hints->max_width = width;
|
|
|
|
size_hints->min_height = size_hints->max_height = height;
|
|
|
|
size_hints->flags = PMinSize | PMaxSize;
|
|
|
|
if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
|
|
|
|
if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
|
|
|
|
else size_hints->flags |= PSize;
|
|
|
|
|
|
|
|
wm_hints->flags = InputHint | StateHint;
|
|
|
|
wm_hints->input = True;
|
|
|
|
wm_hints->initial_state = NormalState;
|
|
|
|
class_hints->res_name = "wine";
|
|
|
|
class_hints->res_class = "Wine";
|
|
|
|
|
|
|
|
XStringListToTextProperty( &name, 1, &window_name );
|
|
|
|
XSetWMProperties( display, win, &window_name, &window_name,
|
|
|
|
NULL, 0, size_hints, wm_hints, class_hints );
|
|
|
|
XFree( size_hints );
|
|
|
|
XFree( wm_hints );
|
|
|
|
XFree( class_hints );
|
|
|
|
XFlush( display );
|
|
|
|
wine_tsx11_unlock();
|
2003-09-16 22:24:29 +02:00
|
|
|
/* initialize the available resolutions */
|
2003-10-16 02:21:42 +02:00
|
|
|
dd_modes = X11DRV_Settings_SetHandlers("desktop",
|
|
|
|
X11DRV_desktop_GetCurrentMode,
|
|
|
|
X11DRV_desktop_SetCurrentMode,
|
|
|
|
NUM_DESKTOP_MODES+2, 1);
|
2003-09-16 22:24:29 +02:00
|
|
|
make_modes();
|
2003-10-16 02:21:42 +02:00
|
|
|
X11DRV_Settings_AddDepthModes();
|
|
|
|
dd_mode_count = X11DRV_Settings_GetModeCount();
|
|
|
|
X11DRV_Settings_SetDefaultMode(0);
|
2001-05-16 21:52:29 +02:00
|
|
|
return win;
|
|
|
|
}
|