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
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
)];
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" );
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
);
59 /**************************************************************************
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
;
71 case WM_CLIPBOARDUPDATE
:
74 case WM_DESTROYCLIPBOARD
:
79 return X11DRV_CALL( clipboard_message
, ¶ms
);
82 return DefWindowProcW( hwnd
, msg
, wp
, lp
);
86 /**************************************************************************
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};
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() );
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() );
114 while (GetMessageW( &msg
, 0, 0, 0 )) DispatchMessageW( &msg
);
119 void X11DRV_InitClipboard(void)
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
, ¶ms
);
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
, ¶ms
);