24#include <wx/nonownedwnd.h>
25#include <wx/settings.h>
32#ifdef GDK_WINDOWING_X11
36#ifdef GDK_WINDOWING_WAYLAND
37#include <gdk/gdkwayland.h>
50 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
53 double brightness = ( bg.Red() / 255.0 ) * 0.299 +
54 ( bg.Green() / 255.0 ) * 0.587 +
55 ( bg.Blue() / 255.0 ) * 0.117;
57 return brightness < 0.5;
63 return wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
78 GtkWindow* window = GTK_WINDOW( aWindow->GetHandle() );
81 return gtk_window_is_active( window );
104 case wxCURSOR_BULLSEYE:
126 GtkMenuItem* pMenuItem = GTK_MENU_ITEM( pItem );
127 GtkWidget* child = gtk_bin_get_child( GTK_BIN( pMenuItem ) );
128 GtkCellView* pCellView = GTK_CELL_VIEW( child );
129 GtkCellLayout* pCellLayout = GTK_CELL_LAYOUT( pCellView );
130 GtkCellArea* pCellArea = gtk_cell_layout_get_area( pCellLayout );
132 g_signal_handlers_block_matched( pCellArea, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, userdata );
138 AtkObject* atkObj = gtk_combo_box_get_popup_accessible( GTK_COMBO_BOX( aChoice->m_widget ) );
140 if( !atkObj || !GTK_IS_ACCESSIBLE( atkObj ) )
143 GtkWidget* widget = gtk_accessible_get_widget( GTK_ACCESSIBLE( atkObj ) );
145 if( !widget || !GTK_IS_MENU( widget ) )
148 GtkMenu* menu = GTK_MENU( widget );
158 GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( aChoice->m_widget ) );
163 GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
168 g_object_set( G_OBJECT( cell ),
"ellipsize", PANGO_ELLIPSIZE_END,
nullptr );
171 g_list_free( cells );
179 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
181 if( widget && gtk_check_version( 3, 10, 0 ) == nullptr )
182 val = gtk_widget_get_scale_factor( widget );
197 return wxSize( aWindow->GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
198 aWindow->GetSize().GetY() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y ) );
204 gtk_scrolled_window_set_overlay_scrolling( GTK_SCROLLED_WINDOW( aWindow->GetHandle() ),
211 gboolean allowed = 1;
213 g_object_get( gtk_settings_get_default(),
"gtk-menu-images", &allowed, NULL );
219#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
221static bool wayland_warp_pointer( GtkWidget* aWidget, GdkDisplay* aDisplay, GdkWindow* aWindow,
222 GdkDevice* aPtrDev,
int aX,
int aY );
226static wxPoint s_warped_from;
227static wxPoint s_warped_to;
231 wxPoint wx_pos = wxGetMousePosition();
233 if( wx_pos == s_warped_from )
235 wxLogTrace(
traceWayland, wxS(
"Faked mouse pos %d %d -> %d %d" ), wx_pos.x, wx_pos.y,
236 s_warped_to.x, s_warped_to.y );
243 s_warped_from = wxPoint();
244 s_warped_to = wxPoint();
255 if( !wxGetEnv( wxT(
"WAYLAND_DISPLAY" ),
nullptr ) )
257 aWindow->WarpPointer( aX, aY );
261 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
263 GdkDisplay* disp = gtk_widget_get_display( widget );
264 GdkSeat* seat = gdk_display_get_default_seat( disp );
265 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
267#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
268 if( GDK_IS_WAYLAND_DISPLAY( disp ) )
270 wxPoint initialPos = wxGetMousePosition();
271 GdkWindow* win = aWindow->GTKGetDrawingWindow();
273 if( wayland_warp_pointer( widget, disp, win, ptrdev, aX, aY ) )
275 s_warped_from = initialPos;
276 s_warped_to = aWindow->ClientToScreen( wxPoint( aX, aY ) );
278 wxLogTrace(
traceWayland, wxS(
"Set warped from %d %d to %d %d" ), s_warped_from.x,
279 s_warped_from.y, s_warped_to.x, s_warped_to.y );
283#ifdef GDK_WINDOWING_X11
284 if( GDK_IS_X11_DISPLAY( disp ) )
286 GdkWindow* win = gdk_device_get_window_at_position( ptrdev,
nullptr,
nullptr );
287 GdkCursor* blank_cursor = gdk_cursor_new_for_display( disp, GDK_BLANK_CURSOR );
288 GdkCursor* cur_cursor = gdk_window_get_cursor( win );
291 g_object_ref( cur_cursor );
293 gdk_window_set_cursor( win, blank_cursor );
294 aWindow->WarpPointer( aX, aY );
295 gdk_window_set_cursor( win, cur_cursor );
310#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
312static bool s_wl_initialized =
false;
313static struct wl_compositor* s_wl_compositor = NULL;
314static struct zwp_pointer_constraints_v1* s_wl_pointer_constraints = NULL;
315static struct zwp_confined_pointer_v1* s_wl_confined_pointer = NULL;
316static struct wl_region* s_wl_confinement_region = NULL;
317static bool s_wl_locked_flag =
false;
319static void handle_global(
void* data,
struct wl_registry* registry, uint32_t
name,
320 const char* interface, uint32_t version )
322 if( strcmp( interface, wl_compositor_interface.name ) == 0 )
324 wxLogTrace(
traceWayland,
"handle_global received %s", interface );
326 s_wl_compositor =
static_cast<wl_compositor*
>(
327 wl_registry_bind( registry,
name, &wl_compositor_interface, version ) );
331 wxLogTrace(
traceWayland,
"handle_global received %s", interface );
333 s_wl_pointer_constraints =
static_cast<zwp_pointer_constraints_v1*
>( wl_registry_bind(
338static const struct wl_registry_listener registry_listener = {
339 .global = handle_global,
340 .global_remove = NULL,
343static void confined_handler(
void* data,
struct zwp_confined_pointer_v1* zwp_confined_pointer_v1 )
348static void unconfined_handler(
void* data,
349 struct zwp_confined_pointer_v1* zwp_confined_pointer_v1 )
351 wxLogTrace(
traceWayland, wxS(
"Pointer unconfined" ) );
356 .unconfined = unconfined_handler
359static void locked_handler(
void* data,
struct zwp_locked_pointer_v1* zwp_locked_pointer_v1 )
361 s_wl_locked_flag =
true;
365static void unlocked_handler(
void* data,
struct zwp_locked_pointer_v1* zwp_locked_pointer_v1 )
372 .unlocked = unlocked_handler
379static void initialize_wayland( wl_display* wldisp )
381 if( s_wl_initialized )
386 struct wl_registry* registry = wl_display_get_registry( wldisp );
387 wl_registry_add_listener( registry, ®istry_listener, NULL );
388 wl_display_roundtrip( wldisp );
389 s_wl_initialized =
true;
393struct zwp_locked_pointer_v1* s_wl_locked_pointer = NULL;
395static int s_after_paint_handler_id = 0;
397static void on_frame_clock_after_paint( GdkFrameClock* clock, GtkWidget* widget )
399 if( s_wl_locked_pointer )
402 s_wl_locked_pointer = NULL;
404 wxLogTrace(
traceWayland, wxS(
"after-paint: locked_pointer destroyed" ) );
406 g_signal_handler_disconnect( (gpointer) clock, s_after_paint_handler_id );
407 s_after_paint_handler_id = 0;
410 if( s_wl_confinement_region != NULL )
412 wxLogTrace(
traceWayland, wxS(
"after-paint: Restoring confinement" ) );
414 GdkDisplay* disp = gtk_widget_get_display( widget );
415 GdkSeat* seat = gdk_display_get_default_seat( disp );
416 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
417 GdkWindow* window = gtk_widget_get_window( widget );
419 wl_display* wldisp = gdk_wayland_display_get_wl_display( disp );
420 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( window );
421 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( ptrdev );
424 s_wl_pointer_constraints, wlsurf, wlptr, s_wl_confinement_region,
427 wl_display_roundtrip( wldisp );
433static bool wayland_warp_pointer( GtkWidget* aWidget, GdkDisplay* aDisplay, GdkWindow* aWindow,
434 GdkDevice* aPtrDev,
int aX,
int aY )
436 wl_display* wldisp = gdk_wayland_display_get_wl_display( aDisplay );
437 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( aWindow );
438 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( aPtrDev );
440 if( s_after_paint_handler_id )
443 wxLogTrace(
traceWayland, wxS(
"Not warping: after-paint pending" ) );
447 initialize_wayland( wldisp );
449 if( s_wl_locked_pointer )
452 wxLogTrace(
traceWayland, wxS(
"** Destroying previous locked_pointer **" ) );
454 wl_display_roundtrip( wldisp );
455 s_wl_locked_pointer = NULL;
460 GdkFrameClock* frame_clock = gdk_window_get_frame_clock( aWindow );
461 s_after_paint_handler_id = g_signal_connect_after(
462 frame_clock,
"after-paint", G_CALLBACK( on_frame_clock_after_paint ), aWidget );
465 if( s_wl_confinement_region && s_wl_confined_pointer )
468 wl_display_roundtrip( wldisp );
469 s_wl_confined_pointer = NULL;
472 s_wl_locked_flag =
false;
474 s_wl_locked_pointer =
481 gtk_widget_translate_coordinates( aWidget, gtk_widget_get_toplevel( aWidget ), 0, 0, &wx, &wy );
484 wl_fixed_from_int( aY + wy ) );
487 wl_display_roundtrip( wldisp );
489 return s_wl_locked_flag;
495 wxLogTrace(
traceWayland, wxS(
"InfiniteDragPrepareWindow" ) );
497 if( s_wl_confined_pointer != NULL )
502 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
503 GdkDisplay* disp = gtk_widget_get_display( widget );
505 if( !GDK_IS_WAYLAND_DISPLAY( disp ) )
510 GdkSeat* seat = gdk_display_get_default_seat( disp );
511 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
512 GdkWindow* win = aWindow->GTKGetDrawingWindow();
514 wl_display* wldisp = gdk_wayland_display_get_wl_display( disp );
515 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( win );
516 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( ptrdev );
518 initialize_wayland( wldisp );
520 gint x, y, width, height;
521 gdk_window_get_geometry( gdk_window_get_toplevel( win ), &x, &y, &width, &height );
523 wxLogTrace(
traceWayland, wxS(
"Confine region: %d %d %d %d" ), x, y, width, height );
525 s_wl_confinement_region = wl_compositor_create_region( s_wl_compositor );
526 wl_region_add( s_wl_confinement_region, x, y, width, height );
529 s_wl_pointer_constraints, wlsurf, wlptr, s_wl_confinement_region,
534 wl_display_roundtrip( wldisp );
540 wxLogTrace(
traceWayland, wxS(
"InfiniteDragReleaseWindow" ) );
542 if( s_wl_confined_pointer )
545 s_wl_confined_pointer = NULL;
548 if( s_wl_confinement_region )
550 wl_region_destroy( s_wl_confinement_region );
551 s_wl_confinement_region = NULL;
573 return wxGetMousePosition();
static void zwp_confined_pointer_v1_destroy(struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1)
Destroy the confined pointer object.
static int zwp_confined_pointer_v1_add_listener(struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1, const struct zwp_confined_pointer_v1_listener *listener, void *data)
static void zwp_locked_pointer_v1_set_cursor_position_hint(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1, wl_fixed_t surface_x, wl_fixed_t surface_y)
Set the cursor position hint relative to the top left corner of the surface.
static int zwp_locked_pointer_v1_add_listener(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1, const struct zwp_locked_pointer_v1_listener *listener, void *data)
static void zwp_locked_pointer_v1_destroy(struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1)
Destroy the locked pointer object.
static struct zwp_locked_pointer_v1 * zwp_pointer_constraints_v1_lock_pointer(struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1, struct wl_surface *surface, struct wl_pointer *pointer, struct wl_region *region, uint32_t lifetime)
The lock_pointer request lets the client request to disable movements of the virtual pointer (i....
static struct zwp_confined_pointer_v1 * zwp_pointer_constraints_v1_confine_pointer(struct zwp_pointer_constraints_v1 *zwp_pointer_constraints_v1, struct wl_surface *surface, struct wl_pointer *pointer, struct wl_region *region, uint32_t lifetime)
The confine_pointer request lets the client request to confine the pointer cursor to a given region.
@ ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT
the pointer constraint is defunct once deactivated
static void disable_area_apply_attributes_cb(GtkWidget *pItem, gpointer userdata)
The following two functions are based on the "hack" contained in the attached patch at https://gitlab...
const wxString traceWayland
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
void(* confined)(void *data, struct zwp_confined_pointer_v1 *zwp_confined_pointer_v1)
pointer confined
void(* locked)(void *data, struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1)
lock activation event
const struct wl_interface zwp_pointer_constraints_v1_interface