25#include <wx/nonownedwnd.h>
26#include <wx/settings.h>
33#ifdef GDK_WINDOWING_X11
37#ifdef GDK_WINDOWING_WAYLAND
38#include <gdk/gdkwayland.h>
51 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
54 double brightness = ( bg.Red() / 255.0 ) * 0.299 +
55 ( bg.Green() / 255.0 ) * 0.587 +
56 ( bg.Blue() / 255.0 ) * 0.117;
58 return brightness < 0.5;
64 return wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
72#if( GTK_CHECK_VERSION( 3, 24, 0 ) )
74 GtkWidgetPath*
path = gtk_widget_path_new();
75 GtkStyleContext* sc = gtk_style_context_new();
77 gtk_widget_path_append_type(
path, GTK_TYPE_WINDOW );
78 gtk_widget_path_iter_set_object_name(
path, -1,
"infobar" );
79 gtk_widget_path_iter_add_class(
path, -1,
"info" );
81 gtk_style_context_set_path( sc,
path );
82 gtk_style_context_set_state( sc, GTK_STATE_FLAG_NORMAL );
84 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL,
"background-color", &rgba, NULL );
85 aBgColour = wxColour( *rgba );
86 gdk_rgba_free( rgba );
88 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL,
"color", &rgba, NULL );
89 aFgColour = wxColour( *rgba );
90 gdk_rgba_free( rgba );
95 if( aBgColour.Alpha() == 0 )
97 gtk_widget_path_append_type(
path, G_TYPE_NONE );
98 gtk_widget_path_iter_set_object_name(
path, -1,
"revealer" );
99 gtk_widget_path_append_type(
path, G_TYPE_NONE );
100 gtk_widget_path_iter_set_object_name(
path, -1,
"box" );
102 gtk_style_context_set_path( sc,
path );
103 gtk_style_context_set_state( sc, GTK_STATE_FLAG_NORMAL );
105 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL,
"background-color", &rgba, NULL );
106 aBgColour = wxColour( *rgba );
107 gdk_rgba_free( rgba );
109 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL,
"color", &rgba, NULL );
110 aFgColour = wxColour( *rgba );
111 gdk_rgba_free( rgba );
114 gtk_widget_path_free(
path );
115 g_object_unref( sc );
118 aBgColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOBK );
119 aFgColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOTEXT );
132 wxWindow* tlw = aWindow;
134 while( tlw && !tlw->IsTopLevel() )
135 tlw = tlw->GetParent();
139 GtkWidget* widget =
static_cast<GtkWidget*
>( tlw->GetHandle() );
141 if( widget && GTK_IS_WINDOW( widget ) )
142 gtk_window_present( GTK_WINDOW( widget ) );
152 GtkWindow* window = GTK_WINDOW( aWindow->GetHandle() );
155 return gtk_window_is_active( window );
190 case wxCURSOR_BULLSEYE:
212 GtkMenuItem* pMenuItem = GTK_MENU_ITEM( pItem );
213 GtkWidget* child = gtk_bin_get_child( GTK_BIN( pMenuItem ) );
214 GtkCellView* pCellView = GTK_CELL_VIEW( child );
215 GtkCellLayout* pCellLayout = GTK_CELL_LAYOUT( pCellView );
216 GtkCellArea* pCellArea = gtk_cell_layout_get_area( pCellLayout );
218 g_signal_handlers_block_matched( pCellArea, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, userdata );
224 AtkObject* atkObj = gtk_combo_box_get_popup_accessible( GTK_COMBO_BOX( aChoice->m_widget ) );
226 if( !atkObj || !GTK_IS_ACCESSIBLE( atkObj ) )
229 GtkWidget* widget = gtk_accessible_get_widget( GTK_ACCESSIBLE( atkObj ) );
231 if( !widget || !GTK_IS_MENU( widget ) )
234 GtkMenu* menu = GTK_MENU( widget );
244 GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( aChoice->m_widget ) );
249 GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
254 g_object_set( G_OBJECT( cell ),
"ellipsize", PANGO_ELLIPSIZE_END,
nullptr );
257 g_list_free( cells );
265 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
267 if( widget && gtk_check_version( 3, 10, 0 ) ==
nullptr )
268 val = gtk_widget_get_scale_factor( widget );
283 return wxSize( aWindow->GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
284 aWindow->GetSize().GetY() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y ) );
290 gtk_scrolled_window_set_overlay_scrolling( GTK_SCROLLED_WINDOW( aWindow->GetHandle() ),
297 gboolean allowed = 1;
299 g_object_get( gtk_settings_get_default(),
"gtk-menu-images", &allowed, NULL );
305#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
307static bool wayland_warp_pointer( GtkWidget* aWidget, GdkDisplay* aDisplay, GdkWindow* aWindow,
308 GdkDevice* aPtrDev,
int aX,
int aY );
312static wxPoint s_warped_from;
313static wxPoint s_warped_to;
317 wxPoint wx_pos = wxGetMousePosition();
319 if( wx_pos == s_warped_from )
321 wxLogTrace(
traceWayland, wxS(
"Faked mouse pos %d %d -> %d %d" ), wx_pos.x, wx_pos.y,
322 s_warped_to.x, s_warped_to.y );
329 s_warped_from = wxPoint();
330 s_warped_to = wxPoint();
341 if( !wxGetEnv( wxT(
"WAYLAND_DISPLAY" ),
nullptr ) )
343 aWindow->WarpPointer( aX, aY );
348 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
350 GdkDisplay* disp = gtk_widget_get_display( widget );
351 GdkSeat* seat = gdk_display_get_default_seat( disp );
352 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
354#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
355 if( GDK_IS_WAYLAND_DISPLAY( disp ) )
357 wxPoint initialPos = wxGetMousePosition();
358 GdkWindow* win = aWindow->GTKGetDrawingWindow();
360 if( wayland_warp_pointer( widget, disp, win, ptrdev, aX, aY ) )
362 s_warped_from = initialPos;
363 s_warped_to = aWindow->ClientToScreen( wxPoint( aX, aY ) );
365 wxLogTrace(
traceWayland, wxS(
"Set warped from %d %d to %d %d" ), s_warped_from.x,
366 s_warped_from.y, s_warped_to.x, s_warped_to.y );
371 wxLogTrace(
traceWayland, wxS(
"*** Warp to %d %d failed ***" ), aX, aY );
376#ifdef GDK_WINDOWING_X11
377 if( GDK_IS_X11_DISPLAY( disp ) )
379 GdkWindow* win = gdk_device_get_window_at_position( ptrdev,
nullptr,
nullptr );
380 GdkCursor* blank_cursor = gdk_cursor_new_for_display( disp, GDK_BLANK_CURSOR );
381 GdkCursor* cur_cursor = gdk_window_get_cursor( win );
384 g_object_ref( cur_cursor );
386 gdk_window_set_cursor( win, blank_cursor );
387 aWindow->WarpPointer( aX, aY );
388 gdk_window_set_cursor( win, cur_cursor );
391 g_object_unref( cur_cursor );
394 g_object_unref( blank_cursor );
412 wxWindowGTK* win =
static_cast<wxWindowGTK*
>( aWindow );
415 GtkIMContext* imContext = win->m_imContext;
418 gtk_im_context_focus_out( imContext );
432#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
434static bool s_wl_initialized =
false;
435static struct wl_compositor* s_wl_compositor = NULL;
436static struct zwp_pointer_constraints_v1* s_wl_pointer_constraints = NULL;
437static struct zwp_confined_pointer_v1* s_wl_confined_pointer = NULL;
438static struct wl_region* s_wl_confinement_region = NULL;
439static bool s_wl_locked_flag =
false;
441static void handle_global(
void* data,
struct wl_registry* registry, uint32_t
name,
442 const char* interface, uint32_t version )
444 wxLogTrace(
traceWayland,
"handle_global received %s name %u version %u", interface,
445 (
unsigned int)
name, (
unsigned int) version );
447 if( strcmp( interface, wl_compositor_interface.name ) == 0 )
449 s_wl_compositor =
static_cast<wl_compositor*
>(
450 wl_registry_bind( registry,
name, &wl_compositor_interface, version ) );
454 s_wl_pointer_constraints =
static_cast<zwp_pointer_constraints_v1*
>( wl_registry_bind(
459static void handle_global_remove(
void*,
struct wl_registry*, uint32_t
name )
461 wxLogTrace(
traceWayland,
"handle_global_remove name %u", (
unsigned int)
name );
464static const struct wl_registry_listener registry_listener = {
465 .global = handle_global,
466 .global_remove = handle_global_remove,
469static void confined_handler(
void* data,
struct zwp_confined_pointer_v1* zwp_confined_pointer_v1 )
474static void unconfined_handler(
void* data,
475 struct zwp_confined_pointer_v1* zwp_confined_pointer_v1 )
477 wxLogTrace(
traceWayland, wxS(
"Pointer unconfined" ) );
481 .confined = confined_handler,
482 .unconfined = unconfined_handler
485static void locked_handler(
void* data,
struct zwp_locked_pointer_v1* zwp_locked_pointer_v1 )
487 s_wl_locked_flag =
true;
491static void unlocked_handler(
void* data,
struct zwp_locked_pointer_v1* zwp_locked_pointer_v1 )
497 .locked = locked_handler,
498 .unlocked = unlocked_handler
505static void initialize_wayland( wl_display* wldisp )
507 if( s_wl_initialized )
512 struct wl_registry* registry = wl_display_get_registry( wldisp );
513 wl_registry_add_listener( registry, ®istry_listener, NULL );
514 wl_display_roundtrip( wldisp );
515 s_wl_initialized =
true;
519struct zwp_locked_pointer_v1* s_wl_locked_pointer = NULL;
521static int s_after_paint_handler_id = 0;
523static void on_frame_clock_after_paint( GdkFrameClock* clock, GtkWidget* widget )
525 if( s_wl_locked_pointer )
528 s_wl_locked_pointer = NULL;
530 wxLogTrace(
traceWayland, wxS(
"after-paint: locked_pointer destroyed" ) );
532 g_signal_handler_disconnect( (gpointer) clock, s_after_paint_handler_id );
533 s_after_paint_handler_id = 0;
536 if( s_wl_confinement_region != NULL )
538 wxLogTrace(
traceWayland, wxS(
"after-paint: Restoring confinement" ) );
540 GdkDisplay* disp = gtk_widget_get_display( widget );
541 GdkSeat* seat = gdk_display_get_default_seat( disp );
542 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
543 GdkWindow* window = gtk_widget_get_window( widget );
545 wl_display* wldisp = gdk_wayland_display_get_wl_display( disp );
546 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( window );
547 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( ptrdev );
550 s_wl_pointer_constraints, wlsurf, wlptr, s_wl_confinement_region,
553 wl_display_roundtrip( wldisp );
559static bool wayland_warp_pointer( GtkWidget* aWidget, GdkDisplay* aDisplay, GdkWindow* aWindow,
560 GdkDevice* aPtrDev,
int aX,
int aY )
562 wl_display* wldisp = gdk_wayland_display_get_wl_display( aDisplay );
563 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( aWindow );
564 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( aPtrDev );
566 if( s_after_paint_handler_id )
569 wxLogTrace(
traceWayland, wxS(
"Not warping: after-paint pending" ) );
573 initialize_wayland( wldisp );
575 if( s_wl_locked_pointer )
578 wxLogTrace(
traceWayland, wxS(
"** Destroying previous locked_pointer **" ) );
580 wl_display_roundtrip( wldisp );
581 s_wl_locked_pointer = NULL;
586 GdkFrameClock* frame_clock = gdk_window_get_frame_clock( aWindow );
587 s_after_paint_handler_id = g_signal_connect_after(
588 frame_clock,
"after-paint", G_CALLBACK( on_frame_clock_after_paint ), aWidget );
591 if( s_wl_confinement_region && s_wl_confined_pointer )
594 wl_display_roundtrip( wldisp );
595 s_wl_confined_pointer = NULL;
598 s_wl_locked_flag =
false;
600 s_wl_locked_pointer =
607 gtk_widget_translate_coordinates( aWidget, gtk_widget_get_toplevel( aWidget ), 0, 0, &wx, &wy );
610 wl_fixed_from_int( aY + wy ) );
613 wl_display_roundtrip( wldisp );
614 gtk_widget_queue_draw( aWidget );
617 return s_wl_locked_flag;
623 wxLogTrace(
traceWayland, wxS(
"InfiniteDragPrepareWindow" ) );
625 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
626 GdkDisplay* disp = gtk_widget_get_display( widget );
628 if( GDK_IS_WAYLAND_DISPLAY( disp ) )
630 if( s_wl_confined_pointer != NULL )
635 GdkSeat* seat = gdk_display_get_default_seat( disp );
636 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
637 GdkWindow* win = aWindow->GTKGetDrawingWindow();
639 wl_display* wldisp = gdk_wayland_display_get_wl_display( disp );
640 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( win );
641 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( ptrdev );
643 initialize_wayland( wldisp );
645 gint x, y, width, height;
646 gdk_window_get_geometry( gdk_window_get_toplevel( win ), &x, &y, &width, &height );
648 wxLogTrace(
traceWayland, wxS(
"Confine region: %d %d %d %d" ), x, y, width, height );
650 s_wl_confinement_region = wl_compositor_create_region( s_wl_compositor );
651 wl_region_add( s_wl_confinement_region, x, y, width, height );
654 s_wl_pointer_constraints, wlsurf, wlptr, s_wl_confinement_region,
660 wl_display_roundtrip( wldisp );
662 else if( wxGetEnv( wxT(
"WAYLAND_DISPLAY" ),
nullptr ) )
674 wxLogTrace(
traceWayland, wxS(
"InfiniteDragReleaseWindow" ) );
676 if( s_wl_confined_pointer )
679 s_wl_confined_pointer = NULL;
682 if( s_wl_confinement_region )
684 wl_region_destroy( s_wl_confinement_region );
685 s_wl_confinement_region = NULL;
696 return !wxGetEnv( wxT(
"WAYLAND_DISPLAY" ),
nullptr );
708 return wxGetMousePosition();
719 GtkWidget* widget =
static_cast<GtkWidget*
>( aDialog->GetHandle() );
721 if( widget && GTK_IS_FILE_CHOOSER( widget ) )
722 gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( widget ), FALSE );
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
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
const struct wl_interface zwp_pointer_constraints_v1_interface
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