@@ -793,6 +793,36 @@ draw_event(GtkWidget *widget UNUSED,
793
793
794
794
return FALSE;
795
795
}
796
+
797
+ # if GTK_CHECK_VERSION (3 ,10 ,0 )
798
+ static gboolean
799
+ scale_factor_event (GtkWidget * widget ,
800
+ GParamSpec * pspec UNUSED ,
801
+ gpointer user_data UNUSED )
802
+ {
803
+ if (gui .surface != NULL )
804
+ cairo_surface_destroy (gui .surface );
805
+
806
+ int w , h ;
807
+ gtk_window_get_size (GTK_WINDOW (gui .mainwin ), & w , & h );
808
+ gui .surface = gdk_window_create_similar_surface (
809
+ gtk_widget_get_window (widget ),
810
+ CAIRO_CONTENT_COLOR_ALPHA ,
811
+ w , h );
812
+
813
+ int usable_height = h ;
814
+ if (gtk_socket_id != 0 )
815
+ usable_height -= (gui .char_height - (gui .char_height /2 )); // sic.
816
+
817
+ gui_gtk_form_freeze (GTK_FORM (gui .formwin ));
818
+ gui .force_redraw = 1 ;
819
+ gui_resize_shell (w , usable_height );
820
+ gui_gtk_form_thaw (GTK_FORM (gui .formwin ));
821
+
822
+ return TRUE;
823
+ }
824
+ # endif // GTK_CHECK_VERSION(3,10,0)
825
+
796
826
#else // !GTK_CHECK_VERSION(3,0,0)
797
827
static gint
798
828
expose_event (GtkWidget * widget UNUSED ,
@@ -1667,11 +1697,12 @@ selection_get_cb(GtkWidget *widget UNUSED,
1667
1697
int
1668
1698
gui_mch_early_init_check (int give_message )
1669
1699
{
1670
- char_u * p ;
1700
+ char_u * p , * q ;
1671
1701
1672
1702
// Guess that when $DISPLAY isn't set the GUI can't start.
1673
1703
p = mch_getenv ((char_u * )"DISPLAY" );
1674
- if (p == NULL || * p == NUL )
1704
+ q = mch_getenv ((char_u * )"WAYLAND_DISPLAY" );
1705
+ if ((p == NULL || * p == NUL ) && (q == NULL || * q == NUL ))
1675
1706
{
1676
1707
gui .dying = TRUE;
1677
1708
if (give_message )
@@ -1704,7 +1735,10 @@ gui_mch_init_check(void)
1704
1735
#if GTK_CHECK_VERSION (3 ,10 ,0 )
1705
1736
// Vim currently assumes that Gtk means X11, so it cannot use native Gtk
1706
1737
// support for other backends such as Wayland.
1707
- gdk_set_allowed_backends ("x11" );
1738
+ //
1739
+ // Use an environment variable to enable unfinished Wayland support.
1740
+ if (getenv ("GVIM_ENABLE_WAYLAND" ) == NULL )
1741
+ gdk_set_allowed_backends ("x11" );
1708
1742
#endif
1709
1743
1710
1744
#ifdef FEAT_GUI_GNOME
@@ -2024,6 +2058,10 @@ scroll_event(GtkWidget *widget,
2024
2058
{
2025
2059
int button ;
2026
2060
int_u vim_modifiers ;
2061
+ #if GTK_CHECK_VERSION (3 ,4 ,0 )
2062
+ static double acc_x , acc_y ;
2063
+ static guint32 last_smooth_event_time ;
2064
+ #endif
2027
2065
2028
2066
if (gtk_socket_id != 0 && !gtk_widget_has_focus (widget ))
2029
2067
gtk_widget_grab_focus (widget );
@@ -2042,6 +2080,16 @@ scroll_event(GtkWidget *widget,
2042
2080
case GDK_SCROLL_RIGHT :
2043
2081
button = MOUSE_6 ;
2044
2082
break ;
2083
+ #if GTK_CHECK_VERSION (3 ,4 ,0 )
2084
+ case GDK_SCROLL_SMOOTH :
2085
+ if (event -> time - last_smooth_event_time > 50 )
2086
+ // reset our accumulations after 50ms of silence
2087
+ acc_x = acc_y = 0 ;
2088
+ acc_x += event -> delta_x ;
2089
+ acc_y += event -> delta_y ;
2090
+ last_smooth_event_time = event -> time ;
2091
+ break ;
2092
+ #endif
2045
2093
default : // This shouldn't happen
2046
2094
return FALSE;
2047
2095
}
@@ -2054,8 +2102,38 @@ scroll_event(GtkWidget *widget,
2054
2102
2055
2103
vim_modifiers = modifiers_gdk2mouse (event -> state );
2056
2104
2057
- gui_send_mouse_event (button , (int )event -> x , (int )event -> y ,
2058
- FALSE, vim_modifiers );
2105
+ #if GTK_CHECK_VERSION (3 ,4 ,0 )
2106
+ if (event -> direction == GDK_SCROLL_SMOOTH )
2107
+ {
2108
+ while (acc_x > 1.0 )
2109
+ { // right
2110
+ acc_x = MAX (0.0 , acc_x - 1.0 );
2111
+ gui_send_mouse_event (MOUSE_6 , (int )event -> x , (int )event -> y ,
2112
+ FALSE, vim_modifiers );
2113
+ }
2114
+ while (acc_x < -1.0 )
2115
+ { // left
2116
+ acc_x = MIN (0.0 , acc_x + 1.0 );
2117
+ gui_send_mouse_event (MOUSE_7 , (int )event -> x , (int )event -> y ,
2118
+ FALSE, vim_modifiers );
2119
+ }
2120
+ while (acc_y > 1.0 )
2121
+ { // down
2122
+ acc_y = MAX (0.0 , acc_y - 1.0 );
2123
+ gui_send_mouse_event (MOUSE_5 , (int )event -> x , (int )event -> y ,
2124
+ FALSE, vim_modifiers );
2125
+ }
2126
+ while (acc_y < -1.0 )
2127
+ { // up
2128
+ acc_y = MIN (0.0 , acc_y + 1.0 );
2129
+ gui_send_mouse_event (MOUSE_4 , (int )event -> x , (int )event -> y ,
2130
+ FALSE, vim_modifiers );
2131
+ }
2132
+ }
2133
+ else
2134
+ #endif
2135
+ gui_send_mouse_event (button , (int )event -> x , (int )event -> y ,
2136
+ FALSE, vim_modifiers );
2059
2137
2060
2138
return TRUE;
2061
2139
}
@@ -2509,10 +2587,12 @@ setup_save_yourself(void)
2509
2587
// Fall back to old method
2510
2588
2511
2589
// first get the existing value
2512
- GdkWindow * const mainwin_win = gtk_widget_get_window (gui .mainwin );
2590
+ Display * dpy = gui_mch_get_display ();
2591
+ if (!dpy )
2592
+ return ;
2513
2593
2514
- if ( XGetWMProtocols ( GDK_WINDOW_XDISPLAY ( mainwin_win ),
2515
- GDK_WINDOW_XID (mainwin_win ),
2594
+ GdkWindow * const mainwin_win = gtk_widget_get_window ( gui . mainwin );
2595
+ if ( XGetWMProtocols ( dpy , GDK_WINDOW_XID (mainwin_win ),
2516
2596
& existing_atoms , & count ))
2517
2597
{
2518
2598
Atom * new_atoms ;
@@ -2620,7 +2700,10 @@ mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED)
2620
2700
// When started with "--echo-wid" argument, write window ID on stdout.
2621
2701
if (echo_wid_arg )
2622
2702
{
2623
- printf ("WID: %ld\n" , (long )GDK_WINDOW_XID (mainwin_win ));
2703
+ if (gui_mch_get_display ())
2704
+ printf ("WID: %ld\n" , (long )GDK_WINDOW_XID (mainwin_win ));
2705
+ else
2706
+ printf ("WID: 0\n" );
2624
2707
fflush (stdout );
2625
2708
}
2626
2709
@@ -2655,27 +2738,30 @@ mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED)
2655
2738
setup_save_yourself ();
2656
2739
2657
2740
#ifdef FEAT_CLIENTSERVER
2658
- if (serverName == NULL && serverDelayedStartName != NULL )
2741
+ if (gui_mch_get_display () )
2659
2742
{
2660
- // This is a :gui command in a plain vim with no previous server
2661
- commWindow = GDK_WINDOW_XID (mainwin_win );
2743
+ if (serverName == NULL && serverDelayedStartName != NULL )
2744
+ {
2745
+ // This is a :gui command in a plain vim with no previous server
2746
+ commWindow = GDK_WINDOW_XID (mainwin_win );
2662
2747
2663
- (void )serverRegisterName (GDK_WINDOW_XDISPLAY (mainwin_win ),
2664
- serverDelayedStartName );
2665
- }
2666
- else
2667
- {
2668
- /*
2669
- * Cannot handle "XLib-only" windows with gtk event routines, we'll
2670
- * have to change the "server" registration to that of the main window
2671
- * If we have not registered a name yet, remember the window.
2672
- */
2673
- serverChangeRegisteredWindow (GDK_WINDOW_XDISPLAY (mainwin_win ),
2674
- GDK_WINDOW_XID (mainwin_win ));
2748
+ (void )serverRegisterName (GDK_WINDOW_XDISPLAY (mainwin_win ),
2749
+ serverDelayedStartName );
2750
+ }
2751
+ else
2752
+ {
2753
+ /*
2754
+ * Cannot handle "XLib-only" windows with gtk event routines, we'll
2755
+ * have to change the "server" registration to that of the main window
2756
+ * If we have not registered a name yet, remember the window.
2757
+ */
2758
+ serverChangeRegisteredWindow (GDK_WINDOW_XDISPLAY (mainwin_win ),
2759
+ GDK_WINDOW_XID (mainwin_win ));
2760
+ }
2761
+ gtk_widget_add_events (gui .mainwin , GDK_PROPERTY_CHANGE_MASK );
2762
+ g_signal_connect (G_OBJECT (gui .mainwin ), "property-notify-event" ,
2763
+ G_CALLBACK (property_event ), NULL );
2675
2764
}
2676
- gtk_widget_add_events (gui .mainwin , GDK_PROPERTY_CHANGE_MASK );
2677
- g_signal_connect (G_OBJECT (gui .mainwin ), "property-notify-event" ,
2678
- G_CALLBACK (property_event ), NULL );
2679
2765
#endif
2680
2766
}
2681
2767
@@ -3919,6 +4005,9 @@ gui_mch_init(void)
3919
4005
GDK_BUTTON_PRESS_MASK |
3920
4006
GDK_BUTTON_RELEASE_MASK |
3921
4007
GDK_SCROLL_MASK |
4008
+ #if GTK_CHECK_VERSION (3 ,4 ,0 )
4009
+ GDK_SMOOTH_SCROLL_MASK |
4010
+ #endif
3922
4011
GDK_KEY_PRESS_MASK |
3923
4012
GDK_KEY_RELEASE_MASK |
3924
4013
GDK_POINTER_MOTION_MASK |
@@ -4520,6 +4609,10 @@ gui_mch_open(void)
4520
4609
#endif
4521
4610
g_signal_connect (G_OBJECT (gui .formwin ), "configure-event" ,
4522
4611
G_CALLBACK (form_configure_event ), NULL );
4612
+ #if GTK_CHECK_VERSION (3 ,10 ,0 )
4613
+ g_signal_connect (G_OBJECT (gui .formwin ), "notify::scale-factor" ,
4614
+ G_CALLBACK (scale_factor_event ), NULL );
4615
+ #endif
4523
4616
4524
4617
#ifdef FEAT_DND
4525
4618
// Set up for receiving DND items.
@@ -4603,8 +4696,12 @@ gui_mch_exit(int rc UNUSED)
4603
4696
int
4604
4697
gui_mch_get_winpos (int * x , int * y )
4605
4698
{
4606
- gtk_window_get_position (GTK_WINDOW (gui .mainwin ), x , y );
4607
- return OK ;
4699
+ if (gui_mch_get_display ())
4700
+ {
4701
+ gtk_window_get_position (GTK_WINDOW (gui .mainwin ), x , y );
4702
+ return OK ;
4703
+ }
4704
+ return FAIL ;
4608
4705
}
4609
4706
4610
4707
/*
@@ -6229,9 +6326,10 @@ gui_mch_haskey(char_u *name)
6229
6326
int
6230
6327
gui_get_x11_windis (Window * win , Display * * dis )
6231
6328
{
6232
- if (gui .mainwin != NULL && gtk_widget_get_window (gui .mainwin ) != NULL )
6329
+ Display * dpy = gui_mch_get_display ();
6330
+ if (dpy )
6233
6331
{
6234
- * dis = GDK_WINDOW_XDISPLAY ( gtk_widget_get_window ( gui . mainwin )) ;
6332
+ * dis = dpy ;
6235
6333
* win = GDK_WINDOW_XID (gtk_widget_get_window (gui .mainwin ));
6236
6334
return OK ;
6237
6335
}
@@ -6242,18 +6340,18 @@ gui_get_x11_windis(Window *win, Display **dis)
6242
6340
}
6243
6341
#endif
6244
6342
6245
- #if defined(FEAT_CLIENTSERVER ) \
6246
- || (defined(FEAT_X11 ) && defined(FEAT_CLIPBOARD )) || defined(PROTO )
6247
-
6248
6343
Display *
6249
6344
gui_mch_get_display (void )
6250
6345
{
6251
- if (gui .mainwin != NULL && gtk_widget_get_window (gui .mainwin ) != NULL )
6346
+ if (gui .mainwin != NULL && gtk_widget_get_window (gui .mainwin ) != NULL
6347
+ #if GTK_CHECK_VERSION (3 ,0 ,0 )
6348
+ && GDK_IS_X11_DISPLAY (gtk_widget_get_display (gui .mainwin ))
6349
+ #endif
6350
+ )
6252
6351
return GDK_WINDOW_XDISPLAY (gtk_widget_get_window (gui .mainwin ));
6253
6352
else
6254
6353
return NULL ;
6255
6354
}
6256
- #endif
6257
6355
6258
6356
void
6259
6357
gui_mch_beep (void )
@@ -6915,9 +7013,10 @@ clip_mch_request_selection(Clipboard_T *cbd)
6915
7013
return ;
6916
7014
}
6917
7015
6918
- // Final fallback position - use the X CUT_BUFFER0 store
6919
- yank_cut_buffer0 (GDK_WINDOW_XDISPLAY (gtk_widget_get_window (gui .mainwin )),
6920
- cbd );
7016
+ if (gui_mch_get_display ())
7017
+ // Final fallback position - use the X CUT_BUFFER0 store
7018
+ yank_cut_buffer0 (GDK_WINDOW_XDISPLAY (gtk_widget_get_window (gui .mainwin )),
7019
+ cbd );
6921
7020
}
6922
7021
6923
7022
/*
@@ -7083,9 +7182,11 @@ gui_mch_setmouse(int x, int y)
7083
7182
// Sorry for the Xlib call, but we can't avoid it, since there is no
7084
7183
// internal GDK mechanism present to accomplish this. (and for good
7085
7184
// reason...)
7086
- XWarpPointer (GDK_WINDOW_XDISPLAY (gtk_widget_get_window (gui .drawarea )),
7087
- (Window )0 , GDK_WINDOW_XID (gtk_widget_get_window (gui .drawarea )),
7088
- 0 , 0 , 0U , 0U , x , y );
7185
+ Display * dpy = gui_mch_get_display ();
7186
+ if (dpy )
7187
+ XWarpPointer (dpy , (Window )0 ,
7188
+ GDK_WINDOW_XID (gtk_widget_get_window (gui .drawarea )),
7189
+ 0 , 0 , 0U , 0U , x , y );
7089
7190
}
7090
7191
7091
7192
0 commit comments