/* * X11DRV desktop window handling * * Copyright 2001 Alexandre Julliard * * 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 */ #include "config.h" #include #include #include "wine/winuser16.h" #include "win.h" #include "ddrawi.h" #include "x11drv.h" #include "x11ddraw.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(x11drv); /* desktop window procedure */ static LRESULT WINAPI desktop_winproc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch(message) { case WM_NCCREATE: SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE ); SetDeskWallPaper( (LPSTR)-1 ); return TRUE; case WM_ERASEBKGND: PaintDesktop( (HDC)wParam ); return TRUE; case WM_SYSCOMMAND: if ((wParam & 0xfff0) == SC_CLOSE) ExitWindows( 0, 0 ); break; case WM_SETCURSOR: return (LRESULT)SetCursor( LoadCursorA( 0, (LPSTR)IDC_ARROW ) ); 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; Atom atom = x11drv_atom(WM_DELETE_WINDOW); TlsSetValue( thread_data_tls_index, driver_data ); display = thread_display(); hwnd = GetDesktopWindow(); SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)desktop_winproc ); wine_tsx11_lock(); XSaveContext( display, root_window, winContext, (char *)hwnd ); XChangeProperty ( display, root_window, x11drv_atom(WM_PROTOCOLS), XA_ATOM, 32, PropModeReplace, (unsigned char *)&atom, 1 ); XMapWindow( display, root_window ); wine_tsx11_unlock(); SendMessageW( hwnd, WM_NCCREATE, 0, 0 /* should be CREATESTRUCT */ ); 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) { HANDLE handle = CreateThread( NULL, 0, desktop_thread, TlsGetValue( thread_data_tls_index ), 0, &desktop_tid ); if (!handle) { MESSAGE( "Could not create desktop thread\n" ); ExitProcess(1); } /* we transferred our driver data to the new thread */ TlsSetValue( thread_data_tls_index, NULL ); CloseHandle( handle ); } /* data for resolution changing */ static LPDDHALMODEINFO dd_modes; static unsigned int dd_mode_count; static unsigned int max_width; static unsigned int max_height; static const unsigned int widths[] = {320, 400, 512, 640, 800, 1024, 1152, 1280, 1400, 1600}; static const unsigned int heights[] = {200, 300, 384, 480, 600, 768, 864, 1024, 1050, 1200}; #define NUM_DESKTOP_MODES (sizeof(widths) / sizeof(widths[0])) /* create the mode structures */ static void make_modes(void) { int i; /* original specified desktop size */ X11DRV_Settings_AddOneMode(screen_width, screen_height, 0, 0); for (i=0; imin_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(); X11DRV_handle_desktop_resize( width, height ); return 1; } static int X11DRV_desktop_GetCurrentMode(void) { unsigned int i; DWORD dwBpp = screen_depth; if (dwBpp == 24) dwBpp = 32; for (i=0; imin_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(); /* initialize the available resolutions */ dd_modes = X11DRV_Settings_SetHandlers("desktop", X11DRV_desktop_GetCurrentMode, X11DRV_desktop_SetCurrentMode, NUM_DESKTOP_MODES+2, 1); make_modes(); X11DRV_Settings_AddDepthModes(); dd_mode_count = X11DRV_Settings_GetModeCount(); X11DRV_Settings_SetDefaultMode(0); return win; }