winex11: Introduce X11DRV_CALL macro.
[wine.git] / dlls / winex11.drv / dllmain.c
blob6a9f4a57273d71fd5b650947e6a5440bfc16d5ea
1 /*
2 * winex11.drv entry points
4 * Copyright 2022 Jacek Caban for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "x11drv.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
28 HMODULE x11drv_module = 0;
30 /**************************************************************************
31 * wait_clipboard_mutex
33 * Make sure that there's only one clipboard thread per window station.
35 static BOOL wait_clipboard_mutex(void)
37 static const WCHAR prefix[] = {'_','_','w','i','n','e','_','c','l','i','p','b','o','a','r','d','_'};
38 WCHAR buffer[MAX_PATH + ARRAY_SIZE( prefix )];
39 HANDLE mutex;
41 memcpy( buffer, prefix, sizeof(prefix) );
42 if (!GetUserObjectInformationW( GetProcessWindowStation(), UOI_NAME,
43 buffer + ARRAY_SIZE( prefix ),
44 sizeof(buffer) - sizeof(prefix), NULL ))
46 ERR( "failed to get winstation name\n" );
47 return FALSE;
49 mutex = CreateMutexW( NULL, TRUE, buffer );
50 if (GetLastError() == ERROR_ALREADY_EXISTS)
52 TRACE( "waiting for mutex %s\n", debugstr_w( buffer ));
53 WaitForSingleObject( mutex, INFINITE );
55 return TRUE;
59 /**************************************************************************
60 * clipboard_wndproc
62 * Window procedure for the clipboard manager.
64 static LRESULT CALLBACK clipboard_wndproc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
66 struct clipboard_message_params params;
68 switch (msg)
70 case WM_NCCREATE:
71 case WM_CLIPBOARDUPDATE:
72 case WM_RENDERFORMAT:
73 case WM_TIMER:
74 case WM_DESTROYCLIPBOARD:
75 params.hwnd = hwnd;
76 params.msg = msg;
77 params.wparam = wp;
78 params.lparam = lp;
79 return X11DRV_CALL( clipboard_message, &params );
82 return DefWindowProcW( hwnd, msg, wp, lp );
86 /**************************************************************************
87 * clipboard_thread
89 * Thread running inside the desktop process to manage the clipboard
91 static DWORD WINAPI clipboard_thread( void *arg )
93 static const WCHAR clipboard_classname[] = {'_','_','w','i','n','e','_','c','l','i','p','b','o','a','r','d','_','m','a','n','a','g','e','r',0};
94 WNDCLASSW class;
95 MSG msg;
97 if (!wait_clipboard_mutex()) return 0;
99 memset( &class, 0, sizeof(class) );
100 class.lpfnWndProc = clipboard_wndproc;
101 class.lpszClassName = clipboard_classname;
103 if (!RegisterClassW( &class ) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
105 ERR( "could not register clipboard window class err %u\n", GetLastError() );
106 return 0;
108 if (!CreateWindowW( clipboard_classname, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL ))
110 ERR( "failed to create clipboard window err %u\n", GetLastError() );
111 return 0;
114 while (GetMessageW( &msg, 0, 0, 0 )) DispatchMessageW( &msg );
115 return 0;
119 void X11DRV_InitClipboard(void)
121 DWORD id;
122 HANDLE thread = CreateThread( NULL, 0, clipboard_thread, NULL, 0, &id );
124 if (thread) CloseHandle( thread );
125 else ERR( "failed to create clipboard thread\n" );
129 BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved )
131 if (reason != DLL_PROCESS_ATTACH) return TRUE;
133 DisableThreadLibraryCalls( instance );
134 x11drv_module = instance;
135 return !X11DRV_CALL( init, NULL );
139 /***********************************************************************
140 * wine_create_desktop (winex11.@)
142 BOOL CDECL wine_create_desktop( UINT width, UINT height )
144 struct create_desktop_params params = { .width = width, .height = height };
145 return X11DRV_CALL( create_desktop, &params );
148 /***********************************************************************
149 * AttachEventQueueToTablet (winex11.@)
151 int CDECL X11DRV_AttachEventQueueToTablet( HWND owner )
153 return X11DRV_CALL( tablet_attach_queue, owner );
156 /***********************************************************************
157 * GetCurrentPacket (winex11.@)
159 int CDECL X11DRV_GetCurrentPacket( void *packet )
161 return X11DRV_CALL( tablet_get_packet, packet );
164 /***********************************************************************
165 * LoadTabletInfo (winex11.@)
167 BOOL CDECL X11DRV_LoadTabletInfo( HWND hwnd )
169 return X11DRV_CALL( tablet_load_info, hwnd );
172 /***********************************************************************
173 * WTInfoW (winex11.@)
175 UINT CDECL X11DRV_WTInfoW( UINT category, UINT index, void *output )
177 struct tablet_info_params params;
178 params.category = category;
179 params.index = index;
180 params.output = output;
181 return X11DRV_CALL( tablet_info, &params );