24#include <wx/dataview.h>
26#include <wx/nonownedwnd.h>
27#include <wx/settings.h>
34#ifdef GDK_WINDOWING_X11
38#ifdef GDK_WINDOWING_WAYLAND
39#include <gdk/gdkwayland.h>
52 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
55 double brightness = ( bg.Red() / 255.0 ) * 0.299 +
56 ( bg.Green() / 255.0 ) * 0.587 +
57 ( bg.Blue() / 255.0 ) * 0.117;
59 return brightness < 0.5;
65 return wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
73#if( GTK_CHECK_VERSION( 3, 24, 0 ) )
75 GtkWidgetPath*
path = gtk_widget_path_new();
76 GtkStyleContext* sc = gtk_style_context_new();
78 gtk_widget_path_append_type(
path, GTK_TYPE_WINDOW );
79 gtk_widget_path_iter_set_object_name(
path, -1,
"infobar" );
80 gtk_widget_path_iter_add_class(
path, -1,
"info" );
82 gtk_style_context_set_path( sc,
path );
83 gtk_style_context_set_state( sc, GTK_STATE_FLAG_NORMAL );
85 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL,
"background-color", &rgba, NULL );
86 aBgColour = wxColour( *rgba );
87 gdk_rgba_free( rgba );
89 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL,
"color", &rgba, NULL );
90 aFgColour = wxColour( *rgba );
91 gdk_rgba_free( rgba );
96 if( aBgColour.Alpha() == 0 )
98 gtk_widget_path_append_type(
path, G_TYPE_NONE );
99 gtk_widget_path_iter_set_object_name(
path, -1,
"revealer" );
100 gtk_widget_path_append_type(
path, G_TYPE_NONE );
101 gtk_widget_path_iter_set_object_name(
path, -1,
"box" );
103 gtk_style_context_set_path( sc,
path );
104 gtk_style_context_set_state( sc, GTK_STATE_FLAG_NORMAL );
106 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL,
"background-color", &rgba, NULL );
107 aBgColour = wxColour( *rgba );
108 gdk_rgba_free( rgba );
110 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL,
"color", &rgba, NULL );
111 aFgColour = wxColour( *rgba );
112 gdk_rgba_free( rgba );
115 gtk_widget_path_free(
path );
116 g_object_unref( sc );
119 aBgColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOBK );
120 aFgColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOTEXT );
133 wxWindow* tlw = aWindow;
135 while( tlw && !tlw->IsTopLevel() )
136 tlw = tlw->GetParent();
140 GtkWidget* widget =
static_cast<GtkWidget*
>( tlw->GetHandle() );
142 if( widget && GTK_IS_WINDOW( widget ) )
143 gtk_window_present( GTK_WINDOW( widget ) );
153 GtkWindow* window = GTK_WINDOW( aWindow->GetHandle() );
156 return gtk_window_is_active( window );
174 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
176 if( widget && GTK_IS_WINDOW( widget ) )
177 gtk_window_set_gravity( GTK_WINDOW( widget ), GDK_GRAVITY_STATIC );
203 case wxCURSOR_BULLSEYE:
225 GtkMenuItem* pMenuItem = GTK_MENU_ITEM( pItem );
226 GtkWidget* child = gtk_bin_get_child( GTK_BIN( pMenuItem ) );
227 GtkCellView* pCellView = GTK_CELL_VIEW( child );
228 GtkCellLayout* pCellLayout = GTK_CELL_LAYOUT( pCellView );
229 GtkCellArea* pCellArea = gtk_cell_layout_get_area( pCellLayout );
231 g_signal_handlers_block_matched( pCellArea, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, userdata );
237 AtkObject* atkObj = gtk_combo_box_get_popup_accessible( GTK_COMBO_BOX( aChoice->m_widget ) );
239 if( !atkObj || !GTK_IS_ACCESSIBLE( atkObj ) )
242 GtkWidget* widget = gtk_accessible_get_widget( GTK_ACCESSIBLE( atkObj ) );
244 if( !widget || !GTK_IS_MENU( widget ) )
247 GtkMenu* menu = GTK_MENU( widget );
257 GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( aChoice->m_widget ) );
262 GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
267 g_object_set( G_OBJECT( cell ),
"ellipsize", PANGO_ELLIPSIZE_END,
nullptr );
270 g_list_free( cells );
278 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
280 if( widget && gtk_check_version( 3, 10, 0 ) ==
nullptr )
281 val = gtk_widget_get_scale_factor( widget );
296 return wxSize( aWindow->GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
297 aWindow->GetSize().GetY() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y ) );
303 gtk_scrolled_window_set_overlay_scrolling( GTK_SCROLLED_WINDOW( aWindow->GetHandle() ),
310 gboolean allowed = 1;
312 g_object_get( gtk_settings_get_default(),
"gtk-menu-images", &allowed, NULL );
318#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
320static bool wayland_warp_pointer( GtkWidget* aWidget, GdkDisplay* aDisplay, GdkWindow* aWindow,
321 GdkDevice* aPtrDev,
int aX,
int aY );
325static wxPoint s_warped_from;
326static wxPoint s_warped_to;
330 wxPoint wx_pos = wxGetMousePosition();
332 if( wx_pos == s_warped_from )
334 wxLogTrace(
traceWayland, wxS(
"Faked mouse pos %d %d -> %d %d" ), wx_pos.x, wx_pos.y,
335 s_warped_to.x, s_warped_to.y );
342 s_warped_from = wxPoint();
343 s_warped_to = wxPoint();
354 if( !wxGetEnv( wxT(
"WAYLAND_DISPLAY" ),
nullptr ) )
356 aWindow->WarpPointer( aX, aY );
361 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
363 GdkDisplay* disp = gtk_widget_get_display( widget );
364 GdkSeat* seat = gdk_display_get_default_seat( disp );
365 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
367#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
368 if( GDK_IS_WAYLAND_DISPLAY( disp ) )
370 wxPoint initialPos = wxGetMousePosition();
371 GdkWindow* win = aWindow->GTKGetDrawingWindow();
373 if( wayland_warp_pointer( widget, disp, win, ptrdev, aX, aY ) )
375 s_warped_from = initialPos;
376 s_warped_to = aWindow->ClientToScreen( wxPoint( aX, aY ) );
378 wxLogTrace(
traceWayland, wxS(
"Set warped from %d %d to %d %d" ), s_warped_from.x,
379 s_warped_from.y, s_warped_to.x, s_warped_to.y );
384 wxLogTrace(
traceWayland, wxS(
"*** Warp to %d %d failed ***" ), aX, aY );
389#ifdef GDK_WINDOWING_X11
390 if( GDK_IS_X11_DISPLAY( disp ) )
392 GdkWindow* win = gdk_device_get_window_at_position( ptrdev,
nullptr,
nullptr );
393 GdkCursor* blank_cursor = gdk_cursor_new_for_display( disp, GDK_BLANK_CURSOR );
394 GdkCursor* cur_cursor = gdk_window_get_cursor( win );
397 g_object_ref( cur_cursor );
399 gdk_window_set_cursor( win, blank_cursor );
400 aWindow->WarpPointer( aX, aY );
401 gdk_window_set_cursor( win, cur_cursor );
404 g_object_unref( cur_cursor );
407 g_object_unref( blank_cursor );
425 wxWindowGTK* win =
static_cast<wxWindowGTK*
>( aWindow );
428 GtkIMContext* imContext = win->m_imContext;
431 gtk_im_context_focus_out( imContext );
450 GtkWidget* widget =
static_cast<GtkWidget*
>( aDialog->GetHandle() );
452 if( widget && GTK_IS_FILE_CHOOSER( widget ) )
453 gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( widget ), FALSE );
462 GtkWidget* widget = aCtrl->GtkGetTreeView();
464 if( !widget || !GTK_IS_TREE_VIEW( widget ) )
467 GtkTreeView* view = GTK_TREE_VIEW( widget );
470 if( !gtk_tree_view_get_model( view ) )
473 GtkTreeViewColumn* column = gtk_tree_view_get_column( view, 0 );
484 gtk_widget_queue_resize( widget );
485 gtk_tree_view_scroll_to_cell( view,
nullptr, column, FALSE, 0.0, 0.0 );
492#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
494static bool s_wl_initialized =
false;
495static struct wl_compositor* s_wl_compositor = NULL;
496static struct zwp_pointer_constraints_v1* s_wl_pointer_constraints = NULL;
497static struct zwp_confined_pointer_v1* s_wl_confined_pointer = NULL;
498static struct wl_region* s_wl_confinement_region = NULL;
499static bool s_wl_locked_flag =
false;
501static void handle_global(
void* data,
struct wl_registry* registry, uint32_t
name,
502 const char* interface, uint32_t version )
504 wxLogTrace(
traceWayland,
"handle_global received %s name %u version %u", interface,
505 (
unsigned int)
name, (
unsigned int) version );
507 if( strcmp( interface, wl_compositor_interface.name ) == 0 )
509 s_wl_compositor =
static_cast<wl_compositor*
>(
510 wl_registry_bind( registry,
name, &wl_compositor_interface, version ) );
514 s_wl_pointer_constraints =
static_cast<zwp_pointer_constraints_v1*
>( wl_registry_bind(
519static void handle_global_remove(
void*,
struct wl_registry*, uint32_t
name )
521 wxLogTrace(
traceWayland,
"handle_global_remove name %u", (
unsigned int)
name );
524static const struct wl_registry_listener registry_listener = {
525 .global = handle_global,
526 .global_remove = handle_global_remove,
529static void confined_handler(
void* data,
struct zwp_confined_pointer_v1* zwp_confined_pointer_v1 )
534static void unconfined_handler(
void* data,
535 struct zwp_confined_pointer_v1* zwp_confined_pointer_v1 )
537 wxLogTrace(
traceWayland, wxS(
"Pointer unconfined" ) );
541 .confined = confined_handler,
542 .unconfined = unconfined_handler
545static void locked_handler(
void* data,
struct zwp_locked_pointer_v1* zwp_locked_pointer_v1 )
547 s_wl_locked_flag =
true;
551static void unlocked_handler(
void* data,
struct zwp_locked_pointer_v1* zwp_locked_pointer_v1 )
557 .locked = locked_handler,
558 .unlocked = unlocked_handler
565static void initialize_wayland( wl_display* wldisp )
567 if( s_wl_initialized )
572 struct wl_registry* registry = wl_display_get_registry( wldisp );
573 wl_registry_add_listener( registry, ®istry_listener, NULL );
574 wl_display_roundtrip( wldisp );
575 s_wl_initialized =
true;
579struct zwp_locked_pointer_v1* s_wl_locked_pointer = NULL;
581static int s_after_paint_handler_id = 0;
583static void on_frame_clock_after_paint( GdkFrameClock* clock, GtkWidget* widget )
585 if( s_wl_locked_pointer )
588 s_wl_locked_pointer = NULL;
590 wxLogTrace(
traceWayland, wxS(
"after-paint: locked_pointer destroyed" ) );
592 g_signal_handler_disconnect( (gpointer) clock, s_after_paint_handler_id );
593 s_after_paint_handler_id = 0;
596 if( s_wl_confinement_region != NULL )
598 wxLogTrace(
traceWayland, wxS(
"after-paint: Restoring confinement" ) );
600 GdkDisplay* disp = gtk_widget_get_display( widget );
601 GdkSeat* seat = gdk_display_get_default_seat( disp );
602 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
603 GdkWindow* window = gtk_widget_get_window( widget );
605 wl_display* wldisp = gdk_wayland_display_get_wl_display( disp );
606 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( window );
607 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( ptrdev );
610 s_wl_pointer_constraints, wlsurf, wlptr, s_wl_confinement_region,
613 wl_display_roundtrip( wldisp );
619static bool wayland_warp_pointer( GtkWidget* aWidget, GdkDisplay* aDisplay, GdkWindow* aWindow,
620 GdkDevice* aPtrDev,
int aX,
int aY )
622 wl_display* wldisp = gdk_wayland_display_get_wl_display( aDisplay );
623 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( aWindow );
624 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( aPtrDev );
626 if( s_after_paint_handler_id )
629 wxLogTrace(
traceWayland, wxS(
"Not warping: after-paint pending" ) );
633 initialize_wayland( wldisp );
635 if( s_wl_locked_pointer )
638 wxLogTrace(
traceWayland, wxS(
"** Destroying previous locked_pointer **" ) );
640 wl_display_roundtrip( wldisp );
641 s_wl_locked_pointer = NULL;
646 GdkFrameClock* frame_clock = gdk_window_get_frame_clock( aWindow );
647 s_after_paint_handler_id = g_signal_connect_after(
648 frame_clock,
"after-paint", G_CALLBACK( on_frame_clock_after_paint ), aWidget );
651 if( s_wl_confinement_region && s_wl_confined_pointer )
654 wl_display_roundtrip( wldisp );
655 s_wl_confined_pointer = NULL;
658 s_wl_locked_flag =
false;
660 s_wl_locked_pointer =
667 gtk_widget_translate_coordinates( aWidget, gtk_widget_get_toplevel( aWidget ), 0, 0, &wx, &wy );
670 wl_fixed_from_int( aY + wy ) );
673 wl_display_roundtrip( wldisp );
674 gtk_widget_queue_draw( aWidget );
677 return s_wl_locked_flag;
683 wxLogTrace(
traceWayland, wxS(
"InfiniteDragPrepareWindow" ) );
685 GtkWidget* widget =
static_cast<GtkWidget*
>( aWindow->GetHandle() );
686 GdkDisplay* disp = gtk_widget_get_display( widget );
688 if( GDK_IS_WAYLAND_DISPLAY( disp ) )
690 if( s_wl_confined_pointer != NULL )
695 GdkSeat* seat = gdk_display_get_default_seat( disp );
696 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
697 GdkWindow* win = aWindow->GTKGetDrawingWindow();
699 wl_display* wldisp = gdk_wayland_display_get_wl_display( disp );
700 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( win );
701 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( ptrdev );
703 initialize_wayland( wldisp );
705 gint x, y, width, height;
706 gdk_window_get_geometry( gdk_window_get_toplevel( win ), &x, &y, &width, &height );
708 wxLogTrace(
traceWayland, wxS(
"Confine region: %d %d %d %d" ), x, y, width, height );
710 s_wl_confinement_region = wl_compositor_create_region( s_wl_compositor );
711 wl_region_add( s_wl_confinement_region, x, y, width, height );
714 s_wl_pointer_constraints, wlsurf, wlptr, s_wl_confinement_region,
720 wl_display_roundtrip( wldisp );
722 else if( wxGetEnv( wxT(
"WAYLAND_DISPLAY" ),
nullptr ) )
734 wxLogTrace(
traceWayland, wxS(
"InfiniteDragReleaseWindow" ) );
736 if( s_wl_confined_pointer )
739 s_wl_confined_pointer = NULL;
742 if( s_wl_confinement_region )
744 wl_region_destroy( s_wl_confinement_region );
745 s_wl_confinement_region = NULL;
756 return !wxGetEnv( wxT(
"WAYLAND_DISPLAY" ),
nullptr );
768 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
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