KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wxgtk/ui.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 Ian McInerney <Ian.S.McInerney at ieee.org>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <kiplatform/ui.h>
22
23#include <algorithm>
24
25#include <wx/choice.h>
26#include <wx/dataview.h>
27#include <wx/dialog.h>
28#include <wx/display.h>
29#include <wx/nonownedwnd.h>
30#include <wx/popupwin.h>
31#include <wx/settings.h>
32#include <wx/window.h>
33#include <wx/log.h>
34
35#include <gtk/gtk.h>
36#include <gdk/gdk.h>
37
38#ifdef GDK_WINDOWING_X11
39#include <gdk/gdkx.h>
40#include <X11/Xlib.h>
41#include <X11/Xutil.h>
42#endif
43
44#ifdef GDK_WINDOWING_WAYLAND
45#include <gdk/gdkwayland.h>
46#endif
47
48#ifdef KICAD_WAYLAND
50#endif
51
52// Set WXTRACE=KICAD_WAYLAND to see logs
53const wxString traceWayland = wxS( "KICAD_WAYLAND" );
54static const wxChar traceRhi[] = wxT( "KICAD_RHI" );
55
56
58{
59 wxColour bg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
60
61 // Weighted W3C formula
62 double brightness = ( bg.Red() / 255.0 ) * 0.299 +
63 ( bg.Green() / 255.0 ) * 0.587 +
64 ( bg.Blue() / 255.0 ) * 0.117;
65
66 return brightness < 0.5;
67}
68
69
71{
72 return wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
73}
74
75
76void KIPLATFORM::UI::GetInfoBarColours( wxColour& aFgColour, wxColour& aBgColour )
77{
78 // The GTK3.24 way of getting the colours is to use the style context
79 // Earlier GTKs should be able to use the system settings
80#if( GTK_CHECK_VERSION( 3, 24, 0 ) )
81 GdkRGBA* rgba;
82 GtkWidgetPath* path = gtk_widget_path_new();
83 GtkStyleContext* sc = gtk_style_context_new();
84
85 gtk_widget_path_append_type( path, GTK_TYPE_WINDOW );
86 gtk_widget_path_iter_set_object_name( path, -1, "infobar" );
87 gtk_widget_path_iter_add_class( path, -1, "info" );
88
89 gtk_style_context_set_path( sc, path );
90 gtk_style_context_set_state( sc, GTK_STATE_FLAG_NORMAL );
91
92 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL, "background-color", &rgba, NULL );
93 aBgColour = wxColour( *rgba );
94 gdk_rgba_free( rgba );
95
96 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL, "color", &rgba, NULL );
97 aFgColour = wxColour( *rgba );
98 gdk_rgba_free( rgba );
99
100 // Some GTK themes use the plain infobar style, but if they don't, the background alpha
101 // is generally 0. In this case, try the revealer and box as these are used for Adwaita
102 // and other themes.
103 if( aBgColour.Alpha() == 0 )
104 {
105 gtk_widget_path_append_type( path, G_TYPE_NONE );
106 gtk_widget_path_iter_set_object_name( path, -1, "revealer" );
107 gtk_widget_path_append_type( path, G_TYPE_NONE );
108 gtk_widget_path_iter_set_object_name( path, -1, "box" );
109
110 gtk_style_context_set_path( sc, path );
111 gtk_style_context_set_state( sc, GTK_STATE_FLAG_NORMAL );
112
113 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL, "background-color", &rgba, NULL );
114 aBgColour = wxColour( *rgba );
115 gdk_rgba_free( rgba );
116
117 gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL, "color", &rgba, NULL );
118 aFgColour = wxColour( *rgba );
119 gdk_rgba_free( rgba );
120 }
121
122 gtk_widget_path_free( path );
123 g_object_unref( sc );
124
125#else
126 aBgColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOBK );
127 aFgColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOTEXT );
128#endif
129
130}
131
132
133#ifdef GDK_WINDOWING_WAYLAND
134// Holds widgets over a canvas whose OpenGL subsurface covers everything GTK draws in the frame
135// Subsurfaces stack in the order they are mapped, so this one is remapped after the canvas
136class CANVAS_OVERLAY : public wxPopupWindow
137{
138public:
139 CANVAS_OVERLAY( wxWindow* aCanvas ) :
140 wxPopupWindow( aCanvas )
141 {
142 // wx asks for a compositor popup, and GDK maps a popup with any other hint as a subsurface
143 gtk_window_set_type_hint( GTK_WINDOW( m_widget ), GDK_WINDOW_TYPE_HINT_NORMAL );
144
145 aCanvas->Bind( wxEVT_SIZE, &CANVAS_OVERLAY::onCanvasSize, this );
146 g_signal_connect( aCanvas->GetHandle(), "map", G_CALLBACK( onCanvasMap ), this );
147 }
148
149 ~CANVAS_OVERLAY() override
150 {
151 GetParent()->Unbind( wxEVT_SIZE, &CANVAS_OVERLAY::onCanvasSize, this );
152 g_signal_handlers_disconnect_by_data( GetParent()->GetHandle(), this );
153 }
154
155 void Raise() override
156 {
157 // The canvas maps its surface from a queued event, so wait for that
158 CallAfter( &CANVAS_OVERLAY::remap );
159 }
160
161 bool Show( bool aShow = true ) override
162 {
163 if( aShow )
164 follow();
165
166 return wxPopupWindow::Show( aShow );
167 }
168
169private:
170 static void onCanvasMap( GtkWidget* aWidget, gpointer aOverlay )
171 {
172 static_cast<CANVAS_OVERLAY*>( aOverlay )->Raise();
173 }
174
175 void onCanvasSize( wxSizeEvent& aEvent )
176 {
177 follow();
178 aEvent.Skip();
179 }
180
181 void follow()
182 {
183 // There is no position to follow until the frame is mapped
184 if( gtk_widget_get_mapped( GetParent()->GetHandle() ) )
185 Move( GetParent()->ClientToScreen( wxPoint( 0, 0 ) ) );
186 }
187
188 void remap()
189 {
190 if( !IsShown() )
191 return;
192
193 Hide();
194 Show();
195 }
196};
197#endif
198
199
200wxWindow* KIPLATFORM::UI::CreateCanvasOverlay( wxWindow* aCanvas )
201{
202#ifdef GDK_WINDOWING_WAYLAND
203 if( GDK_IS_WAYLAND_DISPLAY( gdk_display_get_default() ) )
204 return new CANVAS_OVERLAY( aCanvas );
205#endif
206
207 return nullptr;
208}
209
210
211void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
212{
213 aWindow->SetFocus();
214
215 // On GTK, SetFocus() on a dialog may not be sufficient to receive keyboard events
216 // (like ESC for closing). We need to ensure the window is presented and active.
217 // Find the top-level window and present it to ensure keyboard focus.
218 wxWindow* tlw = aWindow;
219
220 while( tlw && !tlw->IsTopLevel() )
221 tlw = tlw->GetParent();
222
223 if( tlw )
224 {
225 GtkWidget* widget = static_cast<GtkWidget*>( tlw->GetHandle() );
226
227 if( widget && GTK_IS_WINDOW( widget ) )
228 gtk_window_present( GTK_WINDOW( widget ) );
229 }
230}
231
232
233bool KIPLATFORM::UI::IsWindowActive( wxWindow* aWindow )
234{
235 if( !aWindow )
236 return false;
237
238 GtkWindow* window = GTK_WINDOW( aWindow->GetHandle() );
239
240 if( window )
241 return gtk_window_is_active( window );
242
243 // We shouldn't really ever reach this point
244 return false;
245}
246
247
249{
250 if( !aWindow )
251 return;
252
253 GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
254
255 if( widget && GTK_IS_WINDOW( widget ) )
256 gtk_window_set_gravity( GTK_WINDOW( widget ), GDK_GRAVITY_STATIC );
257}
258
259
260wxPoint KIPLATFORM::UI::GetRestorablePosition( wxWindow* aWindow )
261{
262 GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
263
264 if( aWindow->IsShown() && widget && GTK_IS_WINDOW( widget )
265 && gtk_window_get_gravity( GTK_WINDOW( widget ) ) == GDK_GRAVITY_STATIC )
266 {
267 if( GdkWindow* gdkWindow = gtk_widget_get_window( widget ) )
268 {
269 wxPoint origin;
270 GdkRectangle frame;
271 gdk_window_get_origin( gdkWindow, &origin.x, &origin.y );
272 gdk_window_get_frame_extents( gdkWindow, &frame );
273
274 // Heal a position that crept up before static gravity, so the title bar comes back on screen
275 int displayIdx = wxDisplay::GetFromWindow( aWindow );
276
277 if( displayIdx != wxNOT_FOUND )
278 {
279 wxRect workArea = wxDisplay( (unsigned int) displayIdx ).GetClientArea();
280 origin.x += std::max( 0, workArea.x - frame.x );
281 origin.y += std::max( 0, workArea.y - frame.y );
282 }
283
284 return origin;
285 }
286 }
287
288 return aWindow->GetPosition();
289}
290
291
292static const char* const WM_CLASS_DATA_KEY = "kicad-wm-class";
293
294
295// Re-assert our application id on the widget's window. Bound to "realize" and "map" because GTK
296// writes WM_CLASS from the program class when it realizes the window, so ours must be applied
297// afterwards to survive; the Wayland application id additionally requires a mapped surface. The
298// id is read from the widget's object data so its lifetime is not tied to the signal closures.
299static void setWindowClassHint( GtkWidget* aWidget, gpointer )
300{
301 const char* id = static_cast<const char*>( g_object_get_data( G_OBJECT( aWidget ),
303
304 if( !id || !*id )
305 return;
306
307 GdkWindow* window = gtk_widget_get_window( aWidget );
308
309 if( !window )
310 return;
311
312#ifdef GDK_WINDOWING_X11
313 if( GDK_IS_X11_WINDOW( window ) )
314 {
315 // wxGTK sets res_class from the app display name; overwrite both WM_CLASS fields with
316 // the desktop id so the window manager matches us to our installed .desktop launcher.
317 if( XClassHint* hints = XAllocClassHint() )
318 {
319 hints->res_name = const_cast<char*>( id );
320 hints->res_class = const_cast<char*>( id );
321
322 XSetClassHint( GDK_WINDOW_XDISPLAY( window ), GDK_WINDOW_XID( window ), hints );
323 XFree( hints );
324 }
325 }
326#endif
327
328#if defined( GDK_WINDOWING_WAYLAND ) && GTK_CHECK_VERSION( 3, 24, 22 )
329 // Covers wx < 3.3.1, which never propagates the class name to the Wayland application id.
330 if( GDK_IS_WAYLAND_WINDOW( window ) && gtk_check_version( 3, 24, 22 ) == nullptr )
331 gdk_wayland_window_set_application_id( window, id );
332#endif
333}
334
335
336void KIPLATFORM::UI::SetWMClass( wxWindow* aWindow, const wxString& aClass )
337{
338 if( !aWindow || aClass.IsEmpty() )
339 return;
340
341 GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
342
343 if( !widget )
344 return;
345
346 // Own a single copy of the id on the widget; it is freed when the widget is destroyed. The
347 // signal handlers read it back from here rather than capturing it, so repeated calls stay safe.
348 g_object_set_data_full( G_OBJECT( widget ), WM_CLASS_DATA_KEY, g_strdup( aClass.utf8_str() ),
349 g_free );
350
351 // Guard against stacking duplicate handlers if this is called more than once for a widget.
352 g_signal_handlers_disconnect_by_func( widget, reinterpret_cast<void*>( setWindowClassHint ),
353 nullptr );
354
355 g_signal_connect_after( widget, "realize", G_CALLBACK( setWindowClassHint ), nullptr );
356 g_signal_connect_after( widget, "map", G_CALLBACK( setWindowClassHint ), nullptr );
357
358 // Apply immediately for windows already realized when this is called.
359 if( gtk_widget_get_realized( widget ) )
360 setWindowClassHint( widget, nullptr );
361}
362
363
364void KIPLATFORM::UI::ReparentModal( wxNonOwnedWindow* aWindow )
365{
366 // Not needed on this platform
367}
368
369
370void KIPLATFORM::UI::ReparentWindow( wxNonOwnedWindow* aWindow, wxTopLevelWindow* aParent )
371{
372 // Not needed on this platform (only relevant for macOS child window ordering)
373}
374
375
377{
378 // Not needed on this platform
379}
380
381
382bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
383{
384 switch( aCursor )
385 {
386 case wxCURSOR_BULLSEYE:
387 case wxCURSOR_HAND:
388 case wxCURSOR_ARROW:
389 case wxCURSOR_BLANK:
390 return true;
391 default:
392 return false;
393 }
394}
395
396
405static void disable_area_apply_attributes_cb( GtkWidget* pItem, gpointer userdata )
406{
407 // GTK needs this enormous chain to get the actual type of item that we want
408 GtkMenuItem* pMenuItem = GTK_MENU_ITEM( pItem );
409 GtkWidget* child = gtk_bin_get_child( GTK_BIN( pMenuItem ) );
410 GtkCellView* pCellView = GTK_CELL_VIEW( child );
411 GtkCellLayout* pCellLayout = GTK_CELL_LAYOUT( pCellView );
412 GtkCellArea* pCellArea = gtk_cell_layout_get_area( pCellLayout );
413
414 g_signal_handlers_block_matched( pCellArea, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, userdata );
415}
416
417
418void KIPLATFORM::UI::LargeChoiceBoxHack( wxChoice* aChoice )
419{
420 AtkObject* atkObj = gtk_combo_box_get_popup_accessible( GTK_COMBO_BOX( aChoice->m_widget ) );
421
422 if( !atkObj || !GTK_IS_ACCESSIBLE( atkObj ) )
423 return;
424
425 GtkWidget* widget = gtk_accessible_get_widget( GTK_ACCESSIBLE( atkObj ) );
426
427 if( !widget || !GTK_IS_MENU( widget ) )
428 return;
429
430 GtkMenu* menu = GTK_MENU( widget );
431
432 gtk_container_foreach( GTK_CONTAINER( menu ), disable_area_apply_attributes_cb, menu );
433}
434
435
436void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
437{
438 // This function is based on the code inside the function post_process_ui in
439 // gtkfilechooserwidget.c
440 GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( aChoice->m_widget ) );
441
442 if( !cells )
443 return;
444
445 GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
446
447 if( !cell )
448 return;
449
450 g_object_set( G_OBJECT( cell ), "ellipsize", PANGO_ELLIPSIZE_END, nullptr );
451
452 // Only the list of cells must be freed, the renderer isn't ours to free
453 g_list_free( cells );
454}
455
456
457double KIPLATFORM::UI::GetPixelScaleFactor( const wxWindow* aWindow )
458{
459 double val = 1.0;
460
461 GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
462
463 if( widget && gtk_check_version( 3, 10, 0 ) == nullptr )
464 val = gtk_widget_get_scale_factor( widget );
465
466 return val;
467}
468
469
470double KIPLATFORM::UI::GetContentScaleFactor( const wxWindow* aWindow )
471{
472 // TODO: Do we need something different here?
473 return GetPixelScaleFactor( aWindow );
474}
475
476
477double KIPLATFORM::UI::GetDisplayRefreshRate( const wxWindow* aWindow )
478{
479#if GTK_CHECK_VERSION( 3, 22, 0 )
480 GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
481 GdkWindow* window = widget ? gtk_widget_get_window( widget ) : nullptr;
482
483 if( !window )
484 return 0.0;
485
486 GdkMonitor* monitor = gdk_display_get_monitor_at_window( gdk_window_get_display( window ), window );
487
488 // GDK reports millihertz, and 0 when it does not know
489 return monitor ? gdk_monitor_get_refresh_rate( monitor ) / 1000.0 : 0.0;
490#else
491 return 0.0;
492#endif
493}
494
495
496wxSize KIPLATFORM::UI::GetUnobscuredSize( const wxWindow* aWindow )
497{
498 return wxSize( aWindow->GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
499 aWindow->GetSize().GetY() - wxSystemSettings::GetMetric( wxSYS_HSCROLL_Y ) );
500}
501
502
503void KIPLATFORM::UI::SetOverlayScrolling( const wxWindow* aWindow, bool overlay )
504{
505 gtk_scrolled_window_set_overlay_scrolling( GTK_SCROLLED_WINDOW( aWindow->GetHandle() ),
506 overlay );
507}
508
509
511{
512 gboolean allowed = 1;
513
514 g_object_get( gtk_settings_get_default(), "gtk-menu-images", &allowed, NULL );
515
516 return !!allowed;
517}
518
519
521{
522#ifdef GDK_WINDOWING_X11
523 GdkDisplay* display = gdk_display_get_default();
524
525 return display && GDK_IS_X11_DISPLAY( display );
526#else
527 return false;
528#endif
529}
530
531
532static gboolean onChoicePopupEvent( GtkWidget* aPopup, GdkEvent* aEvent, gpointer )
533{
534 if( aEvent->type == GDK_KEY_PRESS
535 && ( aEvent->key.keyval == GDK_KEY_Return || aEvent->key.keyval == GDK_KEY_KP_Enter )
536 && ( aEvent->key.state & GDK_SHIFT_MASK ) )
537 {
538 GtkWidget* selected = gtk_menu_shell_get_selected_item( GTK_MENU_SHELL( aPopup ) );
539
540 if( selected )
541 {
542 gtk_menu_shell_activate_item( GTK_MENU_SHELL( aPopup ), selected, TRUE );
543 return TRUE;
544 }
545 }
546
547 return FALSE;
548}
549
550
551static void onChoicePopupHidden( GtkWidget* aPopup, gpointer )
552{
553 g_signal_handlers_disconnect_by_func( aPopup, reinterpret_cast<gpointer>( onChoicePopupEvent ), nullptr );
554 g_signal_handlers_disconnect_by_func( aPopup, reinterpret_cast<gpointer>( onChoicePopupHidden ), nullptr );
555}
556
557
558bool KIPLATFORM::UI::PrepareChoicePopup( wxWindow* aControl )
559{
560 GtkWidget* popup = gtk_grab_get_current();
561
562 if( !GTK_IS_MENU( popup ) || gtk_menu_get_attach_widget( GTK_MENU( popup ) ) != aControl->GetHandle() )
563 return false;
564
565 g_signal_handlers_disconnect_by_func( popup, reinterpret_cast<gpointer>( onChoicePopupEvent ), nullptr );
566 g_signal_handlers_disconnect_by_func( popup, reinterpret_cast<gpointer>( onChoicePopupHidden ), nullptr );
567 g_signal_connect( popup, "event", G_CALLBACK( onChoicePopupEvent ), nullptr );
568 g_signal_connect( popup, "hide", G_CALLBACK( onChoicePopupHidden ), nullptr );
569 return true;
570}
571
572
574{
575 wxKeyEvent key;
576 GdkEvent* event = gtk_get_current_event();
577
578 if( event )
579 {
580 guint keyval = 0;
581
582 if( gdk_event_get_keyval( event, &keyval ) )
583 {
584 switch( keyval )
585 {
586 case GDK_KEY_Return: key.m_keyCode = WXK_RETURN; break;
587 case GDK_KEY_KP_Enter: key.m_keyCode = WXK_NUMPAD_ENTER; break;
588 case GDK_KEY_Escape: key.m_keyCode = WXK_ESCAPE; break;
589 }
590
591 key.SetShiftDown( event->key.state & GDK_SHIFT_MASK );
592 key.SetControlDown( event->key.state & GDK_CONTROL_MASK );
593 key.SetAltDown( event->key.state & GDK_MOD1_MASK );
594 key.SetMetaDown( event->key.state & GDK_META_MASK );
595 }
596
597 gdk_event_free( event );
598 }
599
600 return key;
601}
602
603
604#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
605
606static bool wayland_warp_pointer( GtkWidget* aWidget, GdkDisplay* aDisplay, GdkWindow* aWindow,
607 GdkDevice* aPtrDev, int aX, int aY );
608
609// GDK doesn't know if we've moved the cursor using Wayland pointer constraints.
610// So emulate the actual position here
611static wxPoint s_warped_from;
612static wxPoint s_warped_to;
613
615{
616 wxPoint wx_pos = wxGetMousePosition();
617
618 if( wx_pos == s_warped_from )
619 {
620 wxLogTrace( traceWayland, wxS( "Faked mouse pos %d %d -> %d %d" ), wx_pos.x, wx_pos.y,
621 s_warped_to.x, s_warped_to.y );
622
623 return s_warped_to;
624 }
625 else
626 {
627 // Mouse has moved
628 s_warped_from = wxPoint();
629 s_warped_to = wxPoint();
630 }
631
632 return wx_pos;
633}
634
635#endif
636
637
638bool KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY )
639{
640 if( !wxGetEnv( wxT( "WAYLAND_DISPLAY" ), nullptr ) )
641 {
642 aWindow->WarpPointer( aX, aY );
643 return true;
644 }
645 else
646 {
647 GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
648
649 GdkDisplay* disp = gtk_widget_get_display( widget );
650 GdkSeat* seat = gdk_display_get_default_seat( disp );
651 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
652
653#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
654 if( GDK_IS_WAYLAND_DISPLAY( disp ) )
655 {
656 wxPoint initialPos = wxGetMousePosition();
657 GdkWindow* win = aWindow->GTKGetDrawingWindow();
658
659 if( wayland_warp_pointer( widget, disp, win, ptrdev, aX, aY ) )
660 {
661 s_warped_from = initialPos;
662 s_warped_to = aWindow->ClientToScreen( wxPoint( aX, aY ) );
663
664 wxLogTrace( traceWayland, wxS( "Set warped from %d %d to %d %d" ), s_warped_from.x,
665 s_warped_from.y, s_warped_to.x, s_warped_to.y );
666
667 return true;
668 }
669
670 wxLogTrace( traceWayland, wxS( "*** Warp to %d %d failed ***" ), aX, aY );
671
672 return false;
673 }
674#endif
675#ifdef GDK_WINDOWING_X11
676 if( GDK_IS_X11_DISPLAY( disp ) )
677 {
678 GdkWindow* win = gdk_device_get_window_at_position( ptrdev, nullptr, nullptr );
679
680 if( !win )
681 {
682 aWindow->WarpPointer( aX, aY );
683 return true;
684 }
685
686 GdkCursor* blank_cursor = gdk_cursor_new_for_display( disp, GDK_BLANK_CURSOR );
687 GdkCursor* cur_cursor = gdk_window_get_cursor( win );
688
689 if( cur_cursor )
690 g_object_ref( cur_cursor );
691
692 gdk_window_set_cursor( win, blank_cursor );
693 aWindow->WarpPointer( aX, aY );
694 gdk_window_set_cursor( win, cur_cursor );
695
696 if( cur_cursor )
697 g_object_unref( cur_cursor );
698
699 if( blank_cursor )
700 g_object_unref( blank_cursor );
701
702 return true;
703 }
704#endif
705 }
706
707 return false;
708}
709
710
711void KIPLATFORM::UI::ImmControl( wxWindow* aWindow, bool aEnable )
712{
713}
714
715
717{
718 wxWindowGTK* win = static_cast<wxWindowGTK*>( aWindow );
719 if( win )
720 {
721 GtkIMContext* imContext = win->m_imContext;
722 if( imContext )
723 {
724 gtk_im_context_focus_out( imContext );
725 }
726 }
727}
728
729
730void KIPLATFORM::UI::SetFloatLevel( wxWindow* aWindow )
731{
732}
733
734
735void KIPLATFORM::UI::ReleaseChildWindow( wxNonOwnedWindow* aWindow )
736{
737 // Not needed on this platform
738}
739
740
742{
743 GtkWidget* widget = static_cast<GtkWidget*>( aDialog->GetHandle() );
744
745 if( widget && GTK_IS_FILE_CHOOSER( widget ) )
746 gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( widget ), FALSE );
747}
748
749
750int KIPLATFORM::UI::GetColumnWidth( const wxDataViewColumn* aColumn )
751{
752 int requested = gtk_tree_view_column_get_fixed_width( GTK_TREE_VIEW_COLUMN( aColumn->GetGtkHandle() ) );
753
754 // A column never given a width has no request to report
755 return requested > 0 ? requested : aColumn->GetWidth();
756}
757
758
759void KIPLATFORM::UI::CancelPendingScroll( wxDataViewCtrl* aCtrl )
760{
761 if( !aCtrl )
762 return;
763
764 GtkWidget* widget = aCtrl->GtkGetTreeView();
765
766 if( !widget || !GTK_IS_TREE_VIEW( widget ) )
767 return;
768
769 GtkTreeView* view = GTK_TREE_VIEW( widget );
770
771 // Need a live model and rbtree for the assertions in scroll_to_cell.
772 if( !gtk_tree_view_get_model( view ) )
773 return;
774
775 GtkTreeViewColumn* column = gtk_tree_view_get_column( view, 0 );
776
777 if( !column )
778 return;
779
780 // A column-only scroll_to_cell enters GTK's deferred-scroll path, which frees
781 // priv->scroll_to_path and only installs scroll_to_column. That breaks the race
782 // where validate_visible_area dereferences a stale row reference after a model
783 // reset. The deferred branch is taken when the widget is not yet allocated, when
784 // alloc is pending, or when rows are invalid -- queue_resize forces the latter so
785 // a steady-state widget also takes that branch and actually clears the reference.
786 gtk_widget_queue_resize( widget );
787 gtk_tree_view_scroll_to_cell( view, nullptr, column, FALSE, 0.0, 0.0 );
788}
789
790//
791// **** Wayland hacks ahead ****
792//
793
794#if defined( GDK_WINDOWING_WAYLAND ) && defined( KICAD_WAYLAND )
795
796static bool s_wl_initialized = false;
797static struct wl_compositor* s_wl_compositor = NULL;
798static struct zwp_pointer_constraints_v1* s_wl_pointer_constraints = NULL;
799static struct zwp_confined_pointer_v1* s_wl_confined_pointer = NULL;
800static struct wl_region* s_wl_confinement_region = NULL;
801static bool s_wl_locked_flag = false;
802
803static void handle_global( void* data, struct wl_registry* registry, uint32_t name,
804 const char* interface, uint32_t version )
805{
806 wxLogTrace( traceWayland, "handle_global received %s name %u version %u", interface,
807 (unsigned int) name, (unsigned int) version );
808
809 if( strcmp( interface, wl_compositor_interface.name ) == 0 )
810 {
811 s_wl_compositor = static_cast<wl_compositor*>(
812 wl_registry_bind( registry, name, &wl_compositor_interface, version ) );
813 }
814 else if( strcmp( interface, zwp_pointer_constraints_v1_interface.name ) == 0 )
815 {
816 s_wl_pointer_constraints = static_cast<zwp_pointer_constraints_v1*>( wl_registry_bind(
817 registry, name, &zwp_pointer_constraints_v1_interface, version ) );
818 }
819}
820
821static void handle_global_remove( void*, struct wl_registry*, uint32_t name )
822{
823 wxLogTrace( traceWayland, "handle_global_remove name %u", (unsigned int) name );
824}
825
826static const struct wl_registry_listener registry_listener = {
827 .global = handle_global,
828 .global_remove = handle_global_remove,
829};
830
831static void confined_handler( void* data, struct zwp_confined_pointer_v1* zwp_confined_pointer_v1 )
832{
833 wxLogTrace( traceWayland, wxS( "Pointer confined" ) );
834}
835
836static void unconfined_handler( void* data,
837 struct zwp_confined_pointer_v1* zwp_confined_pointer_v1 )
838{
839 wxLogTrace( traceWayland, wxS( "Pointer unconfined" ) );
840}
841
842static const struct zwp_confined_pointer_v1_listener confined_pointer_listener = {
843 .confined = confined_handler,
844 .unconfined = unconfined_handler
845};
846
847static void locked_handler( void* data, struct zwp_locked_pointer_v1* zwp_locked_pointer_v1 )
848{
849 s_wl_locked_flag = true;
850 wxLogTrace( traceWayland, wxS( "Pointer locked" ) );
851}
852
853static void unlocked_handler( void* data, struct zwp_locked_pointer_v1* zwp_locked_pointer_v1 )
854{
855 wxLogTrace( traceWayland, wxS( "Pointer unlocked" ) );
856}
857
858static const struct zwp_locked_pointer_v1_listener locked_pointer_listener = {
859 .locked = locked_handler,
860 .unlocked = unlocked_handler
861};
862
863
867static void initialize_wayland( wl_display* wldisp )
868{
869 if( s_wl_initialized )
870 {
871 return;
872 }
873
874 struct wl_registry* registry = wl_display_get_registry( wldisp );
875 wl_registry_add_listener( registry, &registry_listener, NULL );
876 wl_display_roundtrip( wldisp );
877 s_wl_initialized = true;
878}
879
880
881struct zwp_locked_pointer_v1* s_wl_locked_pointer = NULL;
882
883static int s_after_paint_handler_id = 0;
884
885static void on_frame_clock_after_paint( GdkFrameClock* clock, GtkWidget* widget )
886{
887 if( s_wl_locked_pointer )
888 {
889 zwp_locked_pointer_v1_destroy( s_wl_locked_pointer );
890 s_wl_locked_pointer = NULL;
891
892 wxLogTrace( traceWayland, wxS( "after-paint: locked_pointer destroyed" ) );
893
894 g_signal_handler_disconnect( (gpointer) clock, s_after_paint_handler_id );
895 s_after_paint_handler_id = 0;
896
897 // restore confinement
898 if( s_wl_confinement_region != NULL )
899 {
900 wxLogTrace( traceWayland, wxS( "after-paint: Restoring confinement" ) );
901
902 GdkDisplay* disp = gtk_widget_get_display( widget );
903 GdkSeat* seat = gdk_display_get_default_seat( disp );
904 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
905 GdkWindow* window = gtk_widget_get_window( widget );
906
907 wl_display* wldisp = gdk_wayland_display_get_wl_display( disp );
908 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( window );
909 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( ptrdev );
910
911 s_wl_confined_pointer = zwp_pointer_constraints_v1_confine_pointer(
912 s_wl_pointer_constraints, wlsurf, wlptr, s_wl_confinement_region,
914
915 zwp_confined_pointer_v1_add_listener( s_wl_confined_pointer, &confined_pointer_listener,
916 NULL );
917
918 wl_display_roundtrip( wldisp );
919 }
920 }
921}
922
923
924static bool wayland_warp_pointer( GtkWidget* aWidget, GdkDisplay* aDisplay, GdkWindow* aWindow,
925 GdkDevice* aPtrDev, int aX, int aY )
926{
927 wl_display* wldisp = gdk_wayland_display_get_wl_display( aDisplay );
928 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( aWindow );
929 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( aPtrDev );
930
931 if( s_after_paint_handler_id )
932 {
933 // Previous paint not done yet
934 wxLogTrace( traceWayland, wxS( "Not warping: after-paint pending" ) );
935 return false;
936 }
937
938 initialize_wayland( wldisp );
939
940 if( s_wl_locked_pointer )
941 {
942 // This shouldn't happen but let's be safe
943 wxLogTrace( traceWayland, wxS( "** Destroying previous locked_pointer **" ) );
944 zwp_locked_pointer_v1_destroy( s_wl_locked_pointer );
945 wl_display_roundtrip( wldisp );
946 s_wl_locked_pointer = NULL;
947 }
948
949 // wl_surface_commit causes an assert on GNOME, but has to be called on KDE
950 // before destroying the locked pointer, so wait until GDK commits the surface.
951 GdkFrameClock* frame_clock = gdk_window_get_frame_clock( aWindow );
952 s_after_paint_handler_id = g_signal_connect_after(
953 frame_clock, "after-paint", G_CALLBACK( on_frame_clock_after_paint ), aWidget );
954
955 // temporary disable confinement to allow pointer warping
956 if( s_wl_confinement_region && s_wl_confined_pointer )
957 {
958 zwp_confined_pointer_v1_destroy( s_wl_confined_pointer );
959 wl_display_roundtrip( wldisp );
960 s_wl_confined_pointer = NULL;
961 }
962
963 s_wl_locked_flag = false;
964
965 s_wl_locked_pointer =
966 zwp_pointer_constraints_v1_lock_pointer( s_wl_pointer_constraints, wlsurf, wlptr, NULL,
968
969 zwp_locked_pointer_v1_add_listener(s_wl_locked_pointer, &locked_pointer_listener, NULL);
970
971 gint wx, wy;
972 gtk_widget_translate_coordinates( aWidget, gtk_widget_get_toplevel( aWidget ), 0, 0, &wx, &wy );
973
974 zwp_locked_pointer_v1_set_cursor_position_hint( s_wl_locked_pointer, wl_fixed_from_int( aX + wx ),
975 wl_fixed_from_int( aY + wy ) );
976
977 // Don't call wl_surface_commit, wait for GDK because of an assert on GNOME.
978 wl_display_roundtrip( wldisp ); // To receive "locked" event.
979 gtk_widget_queue_draw( aWidget ); // Needed on some GNOME environment to trigger
980 // the "after-paint" event handler.
981
982 return s_wl_locked_flag;
983}
984
985
986bool KIPLATFORM::UI::InfiniteDragPrepareWindow( wxWindow* aWindow )
987{
988 wxLogTrace( traceWayland, wxS( "InfiniteDragPrepareWindow" ) );
989
990 GtkWidget* widget = static_cast<GtkWidget*>( aWindow->GetHandle() );
991 GdkDisplay* disp = gtk_widget_get_display( widget );
992
993 if( GDK_IS_WAYLAND_DISPLAY( disp ) )
994 {
996
997 GdkSeat* seat = gdk_display_get_default_seat( disp );
998 GdkDevice* ptrdev = gdk_seat_get_pointer( seat );
999 GdkWindow* win = aWindow->GTKGetDrawingWindow();
1000
1001 wl_display* wldisp = gdk_wayland_display_get_wl_display( disp );
1002 wl_surface* wlsurf = gdk_wayland_window_get_wl_surface( win );
1003 wl_pointer* wlptr = gdk_wayland_device_get_wl_pointer( ptrdev );
1004
1005 initialize_wayland( wldisp );
1006
1007 gint x, y, width, height;
1008 gdk_window_get_geometry( gdk_window_get_toplevel( win ), &x, &y, &width, &height );
1009
1010 wxLogTrace( traceWayland, wxS( "Confine region: %d %d %d %d" ), x, y, width, height );
1011
1012 s_wl_confinement_region = wl_compositor_create_region( s_wl_compositor );
1013 wl_region_add( s_wl_confinement_region, x, y, width, height );
1014
1015 // One constraint per surface, so after-paint confines once the lock is gone
1016 if( s_wl_locked_pointer )
1017 {
1018 wxLogTrace( traceWayland, wxS( "Deferring confinement: warp lock pending" ) );
1019 return true;
1020 }
1021
1022 s_wl_confined_pointer = zwp_pointer_constraints_v1_confine_pointer(
1023 s_wl_pointer_constraints, wlsurf, wlptr, s_wl_confinement_region,
1025
1026 zwp_confined_pointer_v1_add_listener( s_wl_confined_pointer, &confined_pointer_listener,
1027 NULL );
1028
1029 wl_display_roundtrip( wldisp );
1030 }
1031 else if( wxGetEnv( wxT( "WAYLAND_DISPLAY" ), nullptr ) )
1032 {
1033 // Not working under XWayland
1034 return false;
1035 }
1036
1037 return true;
1038};
1039
1040
1042{
1043 wxLogTrace( traceWayland, wxS( "InfiniteDragReleaseWindow" ) );
1044
1045 if( s_wl_confined_pointer )
1046 {
1047 zwp_confined_pointer_v1_destroy( s_wl_confined_pointer );
1048 s_wl_confined_pointer = NULL;
1049 }
1050
1051 if( s_wl_confinement_region )
1052 {
1053 wl_region_destroy( s_wl_confinement_region );
1054 s_wl_confinement_region = NULL;
1055 }
1056};
1057
1058
1059#else // No Wayland support
1060
1061
1063{
1064 // Not working under XWayland
1065 return !wxGetEnv( wxT( "WAYLAND_DISPLAY" ), nullptr );
1066};
1067
1068
1070{
1071 // Not needed on X11
1072};
1073
1074
1076{
1077 return wxGetMousePosition();
1078}
1079
1080
1081#endif
1082
1083
1084void KIPLATFORM::UI::GetNativeWindowHandles( wxWindow* aWindow, void** aHandle, void** aDisplay,
1085 int* aDisplayType )
1086{
1087 *aHandle = nullptr;
1088 *aDisplay = nullptr;
1089
1090 if( aDisplayType )
1092
1093 if( !aWindow )
1094 return;
1095
1096 GtkWidget* gtkWidget = static_cast<GtkWidget*>( aWindow->GetHandle() );
1097
1098 if( !gtkWidget )
1099 return;
1100
1101 gtk_widget_realize( gtkWidget );
1102 GdkWindow* gdkWindow = gtk_widget_get_window( gtkWidget );
1103
1104 if( !gdkWindow )
1105 return;
1106
1107 if( !gdk_window_ensure_native( gdkWindow ) )
1108 {
1109 wxLogTrace( traceRhi, wxS( "GetNativeWindowHandles: gdk_window_ensure_native failed "
1110 "widget=%p window=%p" ),
1111 static_cast<void*>( gtkWidget ),
1112 static_cast<void*>( gdkWindow ) );
1113 return;
1114 }
1115
1116 if( !gdk_window_is_viewable( gdkWindow ) )
1117 {
1118 // Hide() unmaps the GDK window, and mapping it anyway would put a hidden preview canvas back
1119 // on screen over its replacement.
1120 if( !gtk_widget_get_visible( gtkWidget ) )
1121 {
1122 wxLogTrace( traceRhi, wxS( "GetNativeWindowHandles: widget hidden, skipping "
1123 "native window map widget=%p window=%p" ),
1124 static_cast<void*>( gtkWidget ),
1125 static_cast<void*>( gdkWindow ) );
1126 return;
1127 }
1128
1129 wxLogTrace( traceRhi, wxS( "GetNativeWindowHandles: mapping native window "
1130 "widget=%p window=%p mapped=%s viewable=%s" ),
1131 static_cast<void*>( gtkWidget ),
1132 static_cast<void*>( gdkWindow ),
1133 gtk_widget_get_mapped( gtkWidget ) ? "yes" : "no",
1134 gdk_window_is_viewable( gdkWindow ) ? "yes" : "no" );
1135
1136 gdk_window_show_unraised( gdkWindow );
1137
1138 wxLogTrace( traceRhi, wxS( "GetNativeWindowHandles: native window map result "
1139 "window=%p viewable=%s" ),
1140 static_cast<void*>( gdkWindow ),
1141 gdk_window_is_viewable( gdkWindow ) ? "yes" : "no" );
1142 }
1143
1144 GdkDisplay* gdkDisplay = gtk_widget_get_display( gtkWidget );
1145
1146 // The render thread uses its own display connection and must see the window before creating a surface
1147 gdk_display_flush( gdkDisplay );
1148
1149#ifdef GDK_WINDOWING_X11
1150 if( GDK_IS_X11_DISPLAY( gdkDisplay ) )
1151 {
1152 *aHandle = reinterpret_cast<void*>( GDK_WINDOW_XID( gdkWindow ) );
1153 *aDisplay = gdk_x11_display_get_xdisplay( gdkDisplay );
1154
1155 if( aDisplayType )
1156 *aDisplayType = NATIVE_DISPLAY_TYPE::DISPLAY_X11;
1157
1158 wxLogTrace( traceRhi, wxS( "GetNativeWindowHandles: X11 widget=%p window=%p xid=0x%lx "
1159 "display=%p" ),
1160 static_cast<void*>( gtkWidget ),
1161 static_cast<void*>( gdkWindow ),
1162 static_cast<unsigned long>( GDK_WINDOW_XID( gdkWindow ) ),
1163 *aDisplay );
1164 return;
1165 }
1166#endif
1167
1168#ifdef GDK_WINDOWING_WAYLAND
1169 if( GDK_IS_WAYLAND_DISPLAY( gdkDisplay ) )
1170 {
1171 *aHandle = gdk_wayland_window_get_wl_surface( gdkWindow );
1172 *aDisplay = gdk_wayland_display_get_wl_display( gdkDisplay );
1173
1174 if( aDisplayType )
1176
1177 wxLogTrace( traceRhi, wxS( "GetNativeWindowHandles: Wayland widget=%p window=%p "
1178 "surface=%p display=%p" ),
1179 static_cast<void*>( gtkWidget ),
1180 static_cast<void*>( gdkWindow ),
1181 *aHandle,
1182 *aDisplay );
1183 return;
1184 }
1185#endif
1186}
1187
1188
1190{
1191 if( !aWindow )
1192 return;
1193
1194 GtkWidget* gtkWidget = static_cast<GtkWidget*>( aWindow->GetHandle() );
1195
1196 if( !gtkWidget )
1197 {
1198 wxLogTrace( traceRhi, wxS( "PrepareForExternalRendering: no GtkWidget handle" ) );
1199 return;
1200 }
1201
1202 bool realized = gtk_widget_get_realized( gtkWidget );
1203
1204 wxLogTrace( traceRhi, wxS( "PrepareForExternalRendering: widget=%p realized=%s" ),
1205 static_cast<void*>( gtkWidget ), realized ? "yes" : "no" );
1206
1207 // Do not realize here. Before layout that creates a 1x1 X11 window and poisons Vulkan's surface
1208 // capabilities, so GetNativeWindowHandles() realizes it on the first paint instead.
1209
1210 // GTK3's cairo backing surface would otherwise blit over the GPU output after every draw
1211 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1212 gtk_widget_set_double_buffered( gtkWidget, FALSE );
1213 G_GNUC_END_IGNORE_DEPRECATIONS
1214
1215 // Otherwise GTK clears to the GDK background before every draw and flashes black between presents
1216 gtk_widget_set_app_paintable( gtkWidget, TRUE );
1217
1218 wxLogTrace( traceRhi, wxS( "PrepareForExternalRendering: double-buffering disabled, "
1219 "app-paintable enabled" ) );
1220
1221 // Keep areas not yet presented from showing the GTK theme. This needs a realized widget.
1222 if( realized )
1223 {
1224 GdkWindow* gdkWindow = gtk_widget_get_window( gtkWidget );
1225
1226 if( gdkWindow )
1227 {
1228#ifdef GDK_WINDOWING_X11
1229 if( GDK_IS_X11_DISPLAY( gdk_display_get_default() ) )
1230 {
1231 // The X server repaints exposed regions with the BackgroundPixmap before the
1232 // client presents, flashing black; None leaves the previous frame in place.
1233 Display* xDisplay = GDK_DISPLAY_XDISPLAY( gdk_display_get_default() );
1234 Window xWindow = GDK_WINDOW_XID( gdkWindow );
1235 XSetWindowBackgroundPixmap( xDisplay, xWindow, None );
1236
1237 wxLogTrace( traceRhi, wxS( "PrepareForExternalRendering: X11 "
1238 "BackgroundPixmap set to None" ) );
1239 }
1240 else
1241#endif
1242 {
1243 GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
1244
1245 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1246 gdk_window_set_background_rgba( gdkWindow, &black );
1247 G_GNUC_END_IGNORE_DEPRECATIONS
1248
1249 wxLogTrace( traceRhi, wxS( "PrepareForExternalRendering: GDK background "
1250 "set to black" ) );
1251 }
1252 }
1253 else
1254 {
1255 wxLogTrace( traceRhi, wxS( "PrepareForExternalRendering: no GdkWindow" ) );
1256 }
1257
1258 }
1259
1260 // Children shown earlier have been painting into the window the GPU now presents to
1261 for( wxWindow* child : aWindow->GetChildren() )
1263}
1264
1265
1267{
1268#ifdef GDK_WINDOWING_X11
1269 if( !aChild || !aChild->GetParent() )
1270 return;
1271
1272 GtkWidget* child = static_cast<GtkWidget*>( aChild->GetHandle() );
1273 GtkWidget* parent = static_cast<GtkWidget*>( aChild->GetParent()->GetHandle() );
1274
1275 if( !child || !parent || !GDK_IS_X11_DISPLAY( gtk_widget_get_display( child ) ) )
1276 return;
1277
1278 // PrepareForExternalRendering() is what turns double buffering off
1279 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1280 const bool external = !gtk_widget_get_double_buffered( parent );
1281 G_GNUC_END_IGNORE_DEPRECATIONS
1282
1283 if( !external )
1284 return;
1285
1286 GdkWindow* window = gtk_widget_get_window( child );
1287
1288 // A widget without a window of its own reports its parent's
1289 if( !window || window == gtk_widget_get_window( parent ) )
1290 return;
1291
1292 if( !gdk_window_ensure_native( window ) )
1293 wxLogTrace( traceRhi, wxS( "KeepAboveExternalRendering: gdk_window_ensure_native failed" ) );
1294#endif
1295}
const char * name
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
const wxChar *const traceRhi
Flag to enable debug output of the RHI rendering backend.
wxPoint GetRestorablePosition(wxWindow *aWindow)
Return the point that wxWindow::Move() needs to put a stabilized window back where it is.
Definition wxgtk/ui.cpp:260
double GetDisplayRefreshRate(const wxWindow *aWindow)
Return the refresh rate in Hz of the display showing most of the window, or 0 if unknown.
Definition wxgtk/ui.cpp:477
wxWindow * CreateCanvasOverlay(wxWindow *aCanvas)
Create a window for widgets that are shown over a canvas without taking space from it.
Definition wxgtk/ui.cpp:200
bool AllowIconsInMenus()
If the user has disabled icons system-wide, we check that here.
Definition wxgtk/ui.cpp:510
void GetNativeWindowHandles(wxWindow *aWindow, void **aHandle, void **aDisplay, int *aDisplayType=nullptr)
Get the native handles needed to create a GPU surface for aWindow.
void SetFloatLevel(wxWindow *aWindow)
Intended to set the floating window level in macOS on a window.
Definition wxgtk/ui.cpp:730
void GetInfoBarColours(wxColour &aFGColour, wxColour &aBGColour)
Return the background and foreground colors for info bars in the current scheme.
Definition wxgtk/ui.cpp:76
void ReparentWindow(wxNonOwnedWindow *aWindow, wxTopLevelWindow *aParent)
Definition wxgtk/ui.cpp:370
void ReleaseChildWindow(wxNonOwnedWindow *aWindow)
Release a modal window's parent-child relationship with its parent window.
Definition wxgtk/ui.cpp:735
void EllipsizeChoiceBox(wxChoice *aChoice)
Configure a wxChoice control to ellipsize the shown text in the button with the ellipses placed at th...
Definition wxgtk/ui.cpp:436
void PrepareForExternalRendering(wxWindow *aWindow)
Prepare a realized widget for Vulkan or Metal rendering, before its first present.
void FixupCancelButtonCmdKeyCollision(wxWindow *aWindow)
Definition wxgtk/ui.cpp:376
void SetOverlayScrolling(const wxWindow *aWindow, bool overlay)
Used to set overlay/non-overlay scrolling mode in a window.
Definition wxgtk/ui.cpp:503
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
void ImmControl(wxWindow *aWindow, bool aEnable)
Configures the IME mode of a given control handle.
Definition wxgtk/ui.cpp:711
void StabilizeWindowPosition(wxWindow *aWindow)
Prepare a top-level window for reliable position round-tripping.
Definition wxgtk/ui.cpp:248
double GetPixelScaleFactor(const wxWindow *aWindow)
Tries to determine the pixel scaling factor currently in use for the window.
Definition wxgtk/ui.cpp:457
@ DISPLAY_UNKNOWN
Definition ui.h:283
@ DISPLAY_X11
Definition ui.h:284
@ DISPLAY_WAYLAND
Definition ui.h:285
bool PrepareChoicePopup(wxWindow *aControl)
Definition wxgtk/ui.cpp:558
void InfiniteDragReleaseWindow()
On Wayland, allows the cursor to freely move again after a drag (see InfiniteDragPrepareWindow).
int GetColumnWidth(const wxDataViewColumn *aColumn)
The width last asked of aColumn, by SetWidth or by the user dragging its border.
Definition wxgtk/ui.cpp:750
bool IsStockCursorOk(wxStockCursor aCursor)
Checks if we designated a stock cursor for this OS as "OK" or else we may need to load a custom one.
Definition wxgtk/ui.cpp:382
bool SupportsKeyState()
Return whether wxGetKeyState() can query ordinary keys, beyond modifiers and lock keys.
Definition wxgtk/ui.cpp:520
wxKeyEvent GetNativePopupDismissalEvent()
Definition wxgtk/ui.cpp:573
void KeepAboveExternalRendering(wxWindow *aChild)
Keep a child visible on top of a parent prepared with PrepareForExternalRendering().
double GetContentScaleFactor(const wxWindow *aWindow)
Tries to determine the content scaling factor currently in use for the window.
Definition wxgtk/ui.cpp:470
void ImeNotifyCancelComposition(wxWindow *aWindow)
Asks the IME to cancel.
Definition wxgtk/ui.cpp:716
void LargeChoiceBoxHack(wxChoice *aChoice)
Configure a wxChoice control to support a lot of entries by disabling functionality that makes adding...
Definition wxgtk/ui.cpp:418
bool WarpPointer(wxWindow *aWindow, int aX, int aY)
Move the mouse cursor to a specific position relative to the window.
Definition wxgtk/ui.cpp:638
wxColour GetDialogBGColour()
Definition wxgtk/ui.cpp:70
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition wxgtk/ui.cpp:233
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition wxgtk/ui.cpp:496
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition wxgtk/ui.cpp:211
bool InfiniteDragPrepareWindow(wxWindow *aWindow)
On Wayland, restricts the pointer movement to a rectangle slightly bigger than the given wxWindow.
void SetWMClass(wxWindow *aWindow, const wxString &aClass)
Tag a top-level window with the freedesktop application id of its installed launcher,...
Definition wxgtk/ui.cpp:336
void ReparentModal(wxNonOwnedWindow *aWindow)
Move a window's parent to be the top-level window and force the window to be on top.
Definition wxgtk/ui.cpp:364
void CancelPendingScroll(wxDataViewCtrl *aCtrl)
Cancel any pending scroll-to-item request on aCtrl.
Definition wxgtk/ui.cpp:759
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:57
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
std::string path
const struct wl_interface zwp_pointer_constraints_v1_interface
static gboolean onChoicePopupEvent(GtkWidget *aPopup, GdkEvent *aEvent, gpointer)
Definition wxgtk/ui.cpp:532
static const char *const WM_CLASS_DATA_KEY
Definition wxgtk/ui.cpp:292
static void onChoicePopupHidden(GtkWidget *aPopup, gpointer)
Definition wxgtk/ui.cpp:551
static void setWindowClassHint(GtkWidget *aWidget, gpointer)
Definition wxgtk/ui.cpp:299
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...
Definition wxgtk/ui.cpp:405
const wxString traceWayland
Definition wxgtk/ui.cpp:53