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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
|
|
|
|
|
|
|
#include "x11drv.h"
|
2007-12-17 16:24:08 +01:00
|
|
|
|
|
|
|
/* avoid conflict with field names in included win32 headers */
|
|
|
|
#undef Status
|
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
|
|
|
|
2003-09-16 22:24:29 +02:00
|
|
|
/* data for resolution changing */
|
2012-07-03 12:59:43 +02:00
|
|
|
static struct x11drv_mode_info *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;
|
|
|
|
|
2017-01-17 17:06:39 +01:00
|
|
|
static const unsigned int widths[] = {320, 320, 400, 512, 640, 640, 800, 1024, 1152, 1280, 1280, 1400, 1600};
|
|
|
|
static const unsigned int heights[] = {200, 240, 300, 384, 400, 480, 600, 768, 864, 960, 1024, 1050, 1200};
|
2005-07-03 13:20:56 +02:00
|
|
|
#define NUM_DESKTOP_MODES (sizeof(widths) / sizeof(widths[0]))
|
2003-09-16 22:24:29 +02:00
|
|
|
|
2009-05-26 19:54:54 +02:00
|
|
|
#define _NET_WM_STATE_REMOVE 0
|
|
|
|
#define _NET_WM_STATE_ADD 1
|
|
|
|
|
2003-09-16 22:24:29 +02:00
|
|
|
/* create the mode structures */
|
|
|
|
static void make_modes(void)
|
|
|
|
{
|
2013-10-14 14:59:01 +02:00
|
|
|
RECT primary_rect = get_primary_monitor_rect();
|
2008-12-04 23:26:05 +01:00
|
|
|
unsigned int i;
|
2013-10-14 14:59:01 +02:00
|
|
|
unsigned int screen_width = primary_rect.right - primary_rect.left;
|
|
|
|
unsigned int screen_height = primary_rect.bottom - primary_rect.top;
|
|
|
|
|
2003-09-30 02:31:42 +02:00
|
|
|
/* original specified desktop size */
|
2007-03-01 07:57:41 +01:00
|
|
|
X11DRV_Settings_AddOneMode(screen_width, screen_height, 0, 60);
|
2003-10-16 02:21:42 +02:00
|
|
|
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 */
|
2007-03-01 07:57:41 +01:00
|
|
|
X11DRV_Settings_AddOneMode(widths[i], heights[i], 0, 60);
|
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) */
|
2007-03-01 07:57:41 +01:00
|
|
|
X11DRV_Settings_AddOneMode(max_width, max_height, 0, 60);
|
2003-09-16 22:24:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-24 19:10:38 +02:00
|
|
|
static int X11DRV_desktop_GetCurrentMode(void)
|
2003-10-16 02:21:42 +02:00
|
|
|
{
|
2004-08-12 01:45:34 +02:00
|
|
|
unsigned int i;
|
2007-12-16 14:00:45 +01:00
|
|
|
DWORD dwBpp = screen_bpp;
|
2013-10-14 14:59:01 +02:00
|
|
|
RECT primary_rect = get_primary_monitor_rect();
|
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
for (i=0; i<dd_mode_count; i++)
|
|
|
|
{
|
2013-10-14 14:59:01 +02:00
|
|
|
if ( (primary_rect.right - primary_rect.left == dd_modes[i].width) &&
|
|
|
|
(primary_rect.bottom - primary_rect.top == dd_modes[i].height) &&
|
2012-07-03 12:59:43 +02:00
|
|
|
(dwBpp == dd_modes[i].bpp))
|
2003-10-16 02:21:42 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
ERR("In unknown mode, returning default\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-22 12:42:20 +01:00
|
|
|
static LONG X11DRV_desktop_SetCurrentMode(int mode)
|
2003-10-16 02:21:42 +02:00
|
|
|
{
|
2007-12-16 14:00:45 +01:00
|
|
|
DWORD dwBpp = screen_bpp;
|
2012-07-03 12:59:43 +02:00
|
|
|
if (dwBpp != dd_modes[mode].bpp)
|
2003-10-16 02:21:42 +02:00
|
|
|
{
|
2012-07-03 12:59:43 +02:00
|
|
|
FIXME("Cannot change screen BPP from %d to %d\n", dwBpp, dd_modes[mode].bpp);
|
2008-01-04 20:37:14 +01:00
|
|
|
/* Ignore the depth mismatch
|
2007-02-26 13:38:49 +01:00
|
|
|
*
|
|
|
|
* Some (older) applications require a specific bit depth, this will allow them
|
|
|
|
* to run. X11drv performs a color depth conversion if needed.
|
|
|
|
*/
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
2012-07-03 12:59:43 +02:00
|
|
|
TRACE("Resizing Wine desktop window to %dx%d\n", dd_modes[mode].width, dd_modes[mode].height);
|
|
|
|
X11DRV_resize_desktop(dd_modes[mode].width, dd_modes[mode].height);
|
2007-02-22 12:42:20 +01:00
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
2003-10-16 02:21:42 +02:00
|
|
|
}
|
2003-09-16 22:24:29 +02:00
|
|
|
|
2006-03-28 16:55:03 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_init_desktop
|
|
|
|
*
|
|
|
|
* Setup the desktop when not using the root window.
|
|
|
|
*/
|
|
|
|
void X11DRV_init_desktop( Window win, unsigned int width, unsigned int height )
|
|
|
|
{
|
2013-10-14 14:59:01 +02:00
|
|
|
RECT primary_rect = get_primary_monitor_rect();
|
|
|
|
|
2006-03-28 16:55:03 +02:00
|
|
|
root_window = win;
|
2013-11-29 12:33:09 +01:00
|
|
|
managed_mode = FALSE; /* no managed windows in desktop mode */
|
2013-10-14 14:59:01 +02:00
|
|
|
max_width = primary_rect.right - primary_rect.left;
|
|
|
|
max_height = primary_rect.bottom - primary_rect.top;
|
2008-01-17 19:59:22 +01:00
|
|
|
xinerama_init( width, height );
|
2006-03-28 16:55:03 +02:00
|
|
|
|
|
|
|
/* 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-16 21:52:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_create_desktop
|
|
|
|
*
|
|
|
|
* Create the X11 desktop window for the desktop mode.
|
|
|
|
*/
|
2013-02-06 12:49:41 +01:00
|
|
|
BOOL CDECL X11DRV_create_desktop( UINT width, UINT height )
|
2001-05-16 21:52:29 +02:00
|
|
|
{
|
|
|
|
XSetWindowAttributes win_attr;
|
|
|
|
Window win;
|
2008-06-26 16:47:42 +02:00
|
|
|
Display *display = thread_init_display();
|
2013-10-14 14:59:01 +02:00
|
|
|
RECT rect;
|
2001-05-16 21:52:29 +02:00
|
|
|
|
2009-05-28 08:00:10 +02:00
|
|
|
TRACE( "%u x %u\n", width, height );
|
|
|
|
|
2001-05-16 21:52:29 +02:00
|
|
|
/* Create window */
|
2010-05-10 12:34:17 +02:00
|
|
|
win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | EnterWindowMask |
|
2011-05-11 12:07:37 +02:00
|
|
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask | FocusChangeMask;
|
2001-05-16 21:52:29 +02:00
|
|
|
win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
|
|
|
|
|
2012-09-25 15:51:03 +02:00
|
|
|
if (default_visual.visual != DefaultVisual( display, DefaultScreen(display) ))
|
2001-05-16 21:52:29 +02:00
|
|
|
win_attr.colormap = XCreateColormap( display, DefaultRootWindow(display),
|
2012-09-25 15:51:03 +02:00
|
|
|
default_visual.visual, AllocNone );
|
2001-05-16 21:52:29 +02:00
|
|
|
else
|
|
|
|
win_attr.colormap = None;
|
|
|
|
|
|
|
|
win = XCreateWindow( display, DefaultRootWindow(display),
|
2012-09-25 15:51:03 +02:00
|
|
|
0, 0, width, height, 0, default_visual.depth, InputOutput, default_visual.visual,
|
2006-03-27 22:43:03 +02:00
|
|
|
CWEventMask | CWCursor | CWColormap, &win_attr );
|
2013-02-06 12:49:41 +01:00
|
|
|
if (!win) return FALSE;
|
|
|
|
|
2013-10-14 14:59:01 +02:00
|
|
|
SetRect( &rect, 0, 0, width, height );
|
|
|
|
if (is_window_rect_fullscreen( &rect ))
|
2009-05-26 19:54:54 +02:00
|
|
|
{
|
|
|
|
TRACE("setting desktop to fullscreen\n");
|
|
|
|
XChangeProperty( display, win, x11drv_atom(_NET_WM_STATE), XA_ATOM, 32,
|
|
|
|
PropModeReplace, (unsigned char*)&x11drv_atom(_NET_WM_STATE_FULLSCREEN),
|
|
|
|
1);
|
|
|
|
}
|
2013-10-16 12:13:50 +02:00
|
|
|
if (!create_desktop_win_data( win )) return FALSE;
|
2001-05-16 21:52:29 +02:00
|
|
|
XFlush( display );
|
2013-02-06 12:49:41 +01:00
|
|
|
X11DRV_init_desktop( win, width, height );
|
|
|
|
return TRUE;
|
2001-05-16 21:52:29 +02:00
|
|
|
}
|
2008-04-23 15:22:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
struct desktop_resize_data
|
|
|
|
{
|
|
|
|
RECT old_virtual_rect;
|
2013-10-14 14:38:58 +02:00
|
|
|
RECT new_virtual_rect;
|
2008-04-23 15:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
|
|
|
|
{
|
|
|
|
struct x11drv_win_data *data;
|
|
|
|
struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
|
|
|
|
int mask = 0;
|
|
|
|
|
2012-09-24 14:09:43 +02:00
|
|
|
if (!(data = get_win_data( hwnd ))) return TRUE;
|
2008-04-23 15:22:17 +02:00
|
|
|
|
|
|
|
/* update the full screen state */
|
2012-09-21 16:29:24 +02:00
|
|
|
update_net_wm_states( data );
|
2008-04-23 15:22:17 +02:00
|
|
|
|
2013-10-14 14:38:58 +02:00
|
|
|
if (resize_data->old_virtual_rect.left != resize_data->new_virtual_rect.left) mask |= CWX;
|
|
|
|
if (resize_data->old_virtual_rect.top != resize_data->new_virtual_rect.top) mask |= CWY;
|
2008-04-23 15:22:17 +02:00
|
|
|
if (mask && data->whole_window)
|
|
|
|
{
|
2013-10-14 14:20:08 +02:00
|
|
|
POINT pos = virtual_screen_to_root( data->whole_rect.left, data->whole_rect.top );
|
2008-04-23 15:22:17 +02:00
|
|
|
XWindowChanges changes;
|
2013-10-14 14:20:08 +02:00
|
|
|
changes.x = pos.x;
|
|
|
|
changes.y = pos.y;
|
2012-09-26 12:19:37 +02:00
|
|
|
XReconfigureWMWindow( data->display, data->whole_window, data->vis.screen, mask, &changes );
|
2008-04-23 15:22:17 +02:00
|
|
|
}
|
2012-09-24 14:09:43 +02:00
|
|
|
release_win_data( data );
|
2011-05-12 16:24:58 +02:00
|
|
|
if (hwnd == GetForegroundWindow()) clip_fullscreen_window( hwnd, TRUE );
|
2008-04-23 15:22:17 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-08-13 11:39:41 +02:00
|
|
|
BOOL is_desktop_fullscreen(void)
|
|
|
|
{
|
2013-10-14 14:59:01 +02:00
|
|
|
RECT primary_rect = get_primary_monitor_rect();
|
|
|
|
return (primary_rect.right - primary_rect.left == max_width &&
|
|
|
|
primary_rect.bottom - primary_rect.top == max_height);
|
2012-08-13 11:39:41 +02:00
|
|
|
}
|
|
|
|
|
2009-05-26 19:54:54 +02:00
|
|
|
static void update_desktop_fullscreen( unsigned int width, unsigned int height)
|
|
|
|
{
|
|
|
|
Display *display = thread_display();
|
|
|
|
XEvent xev;
|
|
|
|
|
2012-07-13 12:53:11 +02:00
|
|
|
if (!display || root_window == DefaultRootWindow( display )) return;
|
2009-05-26 19:54:54 +02:00
|
|
|
|
|
|
|
xev.xclient.type = ClientMessage;
|
|
|
|
xev.xclient.window = root_window;
|
|
|
|
xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
|
|
|
|
xev.xclient.serial = 0;
|
|
|
|
xev.xclient.display = display;
|
|
|
|
xev.xclient.send_event = True;
|
|
|
|
xev.xclient.format = 32;
|
|
|
|
if (width == max_width && height == max_height)
|
|
|
|
xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
|
|
|
|
else
|
|
|
|
xev.xclient.data.l[0] = _NET_WM_STATE_REMOVE;
|
|
|
|
xev.xclient.data.l[1] = x11drv_atom(_NET_WM_STATE_FULLSCREEN);
|
|
|
|
xev.xclient.data.l[2] = 0;
|
|
|
|
xev.xclient.data.l[3] = 1;
|
|
|
|
|
|
|
|
TRACE("action=%li\n", xev.xclient.data.l[0]);
|
|
|
|
|
2012-08-13 11:39:42 +02:00
|
|
|
XSendEvent( display, DefaultRootWindow(display), False,
|
|
|
|
SubstructureRedirectMask | SubstructureNotifyMask, &xev );
|
|
|
|
|
|
|
|
xev.xclient.data.l[1] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_VERT);
|
|
|
|
xev.xclient.data.l[2] = x11drv_atom(_NET_WM_STATE_MAXIMIZED_HORZ);
|
2009-05-26 19:54:54 +02:00
|
|
|
XSendEvent( display, DefaultRootWindow(display), False,
|
|
|
|
SubstructureRedirectMask | SubstructureNotifyMask, &xev );
|
|
|
|
}
|
2008-04-23 15:22:17 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV_resize_desktop
|
|
|
|
*/
|
|
|
|
void X11DRV_resize_desktop( unsigned int width, unsigned int height )
|
|
|
|
{
|
|
|
|
HWND hwnd = GetDesktopWindow();
|
|
|
|
struct desktop_resize_data resize_data;
|
|
|
|
|
2013-10-14 14:38:58 +02:00
|
|
|
resize_data.old_virtual_rect = get_virtual_screen_rect();
|
2008-04-23 15:22:17 +02:00
|
|
|
|
|
|
|
xinerama_init( width, height );
|
2013-10-14 14:38:58 +02:00
|
|
|
resize_data.new_virtual_rect = get_virtual_screen_rect();
|
2008-04-23 15:22:17 +02:00
|
|
|
|
|
|
|
if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
|
|
|
|
{
|
|
|
|
SendMessageW( hwnd, WM_X11DRV_RESIZE_DESKTOP, 0, MAKELPARAM( width, height ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE( "desktop %p change to (%dx%d)\n", hwnd, width, height );
|
2009-05-26 19:54:54 +02:00
|
|
|
update_desktop_fullscreen( width, height );
|
2013-10-14 14:38:58 +02:00
|
|
|
SetWindowPos( hwnd, 0, resize_data.new_virtual_rect.left, resize_data.new_virtual_rect.top,
|
|
|
|
resize_data.new_virtual_rect.right - resize_data.new_virtual_rect.left,
|
|
|
|
resize_data.new_virtual_rect.bottom - resize_data.new_virtual_rect.top,
|
2008-04-23 15:22:17 +02:00
|
|
|
SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE );
|
2011-04-25 10:49:49 +02:00
|
|
|
ungrab_clipping_window();
|
2008-04-23 15:22:17 +02:00
|
|
|
SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_bpp,
|
|
|
|
MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );
|
|
|
|
}
|