comparison gtk3/dw.c @ 1929:25da63f0eddc

Updates for supporting newer versions of GTK3.... Removes lots of warnings, but we are still using some deprecated funtions for the moment while I decide how to proceed.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 02 Jun 2017 22:49:09 +0000
parents 3c60066cb16f
children fe04bcfd5b65
comparison
equal deleted inserted replaced
1928:e07a1e176995 1929:25da63f0eddc
847 case GDK_BUTTON_PRESS: 847 case GDK_BUTTON_PRESS:
848 if (child->state == CHILD_MAXIMIZED) 848 if (child->state == CHILD_MAXIMIZED)
849 return FALSE; 849 return FALSE;
850 if (mdi->drag_button < 0) 850 if (mdi->drag_button < 0)
851 { 851 {
852 #if GTK_CHECK_VERSION(3,20,0)
853 if (gdk_seat_grab (gdk_event_get_seat(event),
854 event->button.window,
855 GDK_SEAT_CAPABILITY_ALL_POINTING,
856 FALSE, NULL, event, NULL, NULL) != GDK_GRAB_SUCCESS)
857 #else
852 if (gdk_device_grab (gdk_event_get_device(event), 858 if (gdk_device_grab (gdk_event_get_device(event),
853 event->button.window, 859 event->button.window,
854 GDK_OWNERSHIP_WINDOW, 860 GDK_OWNERSHIP_WINDOW,
855 FALSE, 861 FALSE,
856 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | 862 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
857 GDK_BUTTON_RELEASE_MASK, 863 GDK_BUTTON_RELEASE_MASK,
858 NULL, 864 NULL,
859 event->button.time) != GDK_GRAB_SUCCESS) 865 event->button.time) != GDK_GRAB_SUCCESS)
866 #endif
860 return FALSE; 867 return FALSE;
861 868
862 mdi->drag_button = event->button.button; 869 mdi->drag_button = event->button.button;
863 870
864 mdi->drag_start.x = event->button.x; 871 mdi->drag_start.x = event->button.x;
872 879
873 if (mdi->drag_button == event->button.button) 880 if (mdi->drag_button == event->button.button)
874 { 881 {
875 int x, y; 882 int x, y;
876 883
884 #if GTK_CHECK_VERSION(3,20,0)
885 gdk_seat_ungrab (gdk_event_get_seat(event));
886 #else
877 gdk_device_ungrab (gdk_event_get_device(event), event->button.time); 887 gdk_device_ungrab (gdk_event_get_device(event), event->button.time);
888 #endif
878 mdi->drag_button = -1; 889 mdi->drag_button = -1;
879 890
880 x = event->button.x + child->x - mdi->drag_start.x; 891 x = event->button.x + child->x - mdi->drag_start.x;
881 y = event->button.y + child->y - mdi->drag_start.y; 892 y = event->button.y + child->y - mdi->drag_start.y;
882 893
923 switch (event->type) 934 switch (event->type)
924 { 935 {
925 case GDK_BUTTON_PRESS: 936 case GDK_BUTTON_PRESS:
926 if (mdi->drag_button < 0) 937 if (mdi->drag_button < 0)
927 { 938 {
939 #if GTK_CHECK_VERSION(3,20,0)
940 if (gdk_seat_grab (gdk_event_get_seat(event),
941 event->button.window,
942 GDK_SEAT_CAPABILITY_ALL_POINTING,
943 FALSE, NULL, event, NULL, NULL) != GDK_GRAB_SUCCESS)
944 #else
928 if (gdk_device_grab (gdk_event_get_device(event), 945 if (gdk_device_grab (gdk_event_get_device(event),
929 event->button.window, 946 event->button.window,
930 GDK_OWNERSHIP_WINDOW, 947 GDK_OWNERSHIP_WINDOW,
931 FALSE, 948 FALSE,
932 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | 949 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
933 GDK_BUTTON_RELEASE_MASK, 950 GDK_BUTTON_RELEASE_MASK,
934 NULL, 951 NULL,
935 event->button.time) != GDK_GRAB_SUCCESS) 952 event->button.time) != GDK_GRAB_SUCCESS)
953 #endif
936 return FALSE; 954 return FALSE;
937 955
938 mdi->drag_button = event->button.button; 956 mdi->drag_button = event->button.button;
939 if ((child->state == CHILD_MAXIMIZED) || (child->state == CHILD_ICONIFIED)) 957 if ((child->state == CHILD_MAXIMIZED) || (child->state == CHILD_ICONIFIED))
940 { 958 {
958 if (mdi->drag_button == event->button.button) 976 if (mdi->drag_button == event->button.button)
959 { 977 {
960 int width, height; 978 int width, height;
961 GtkAllocation allocation; 979 GtkAllocation allocation;
962 980
981 #if GTK_CHECK_VERSION(3,20,0)
982 gdk_seat_ungrab (gdk_event_get_seat(event));
983 #else
963 gdk_device_ungrab (gdk_event_get_device(event), event->button.time); 984 gdk_device_ungrab (gdk_event_get_device(event), event->button.time);
985 #endif
964 mdi->drag_button = -1; 986 mdi->drag_button = -1;
965 987
966 gtk_widget_get_allocation(widget, &allocation); 988 gtk_widget_get_allocation(widget, &allocation);
967 width = event->button.x + allocation.x; 989 width = event->button.x + allocation.x;
968 height = event->button.y + allocation.y; 990 height = event->button.y + allocation.y;
2925 { 2947 {
2926 /* TODO */ 2948 /* TODO */
2927 return 0; 2949 return 0;
2928 } 2950 }
2929 2951
2930 static GdkDeviceManager *manager = NULL; 2952 #if GTK_CHECK_VERSION(3,20,0)
2953 static GdkSeat *_dw_grab_seat = NULL;
2954 #else
2955 static GdkDeviceManager *_dw_grab_manager = NULL;
2956 #endif
2931 2957
2932 /* 2958 /*
2933 * Captures the mouse input to this window. 2959 * Captures the mouse input to this window.
2934 * Parameters: 2960 * Parameters:
2935 * handle: Handle to receive mouse input. 2961 * handle: Handle to receive mouse input.
2937 void dw_window_capture(HWND handle) 2963 void dw_window_capture(HWND handle)
2938 { 2964 {
2939 int _locked_by_me = FALSE; 2965 int _locked_by_me = FALSE;
2940 2966
2941 DW_MUTEX_LOCK; 2967 DW_MUTEX_LOCK;
2942 manager = gdk_display_get_device_manager(gtk_widget_get_display(handle)); 2968 #if GTK_CHECK_VERSION(3,20,0)
2969 _dw_grab_seat = gdk_display_get_default_seat(gtk_widget_get_display(handle));
2970 gdk_seat_grab (_dw_grab_seat,
2971 gtk_widget_get_window(handle),
2972 GDK_SEAT_CAPABILITY_ALL_POINTING,
2973 FALSE, NULL, NULL, NULL, NULL);
2974 #else
2975 _dw_grab_manager = gdk_display_get_device_manager(gtk_widget_get_display(handle));
2943 gdk_device_grab(gdk_device_manager_get_client_pointer(manager), 2976 gdk_device_grab(gdk_device_manager_get_client_pointer(manager),
2944 gtk_widget_get_window(handle), 2977 gtk_widget_get_window(handle),
2945 GDK_OWNERSHIP_WINDOW, 2978 GDK_OWNERSHIP_WINDOW,
2946 FALSE, 2979 FALSE,
2947 GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, 2980 GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK,
2948 NULL, 2981 NULL,
2949 GDK_CURRENT_TIME); 2982 GDK_CURRENT_TIME);
2983 #endif
2950 DW_MUTEX_UNLOCK; 2984 DW_MUTEX_UNLOCK;
2951 } 2985 }
2952 2986
2953 /* 2987 /*
2954 * Changes the appearance of the mouse pointer. 2988 * Changes the appearance of the mouse pointer.
2984 void dw_window_release(void) 3018 void dw_window_release(void)
2985 { 3019 {
2986 int _locked_by_me = FALSE; 3020 int _locked_by_me = FALSE;
2987 3021
2988 DW_MUTEX_LOCK; 3022 DW_MUTEX_LOCK;
3023 #if GTK_CHECK_VERSION(3,20,0)
3024 if(_dw_grab_seat)
3025 gdk_seat_ungrab(_dw_grab_seat);
3026 _dw_grab_seat = NULL;
3027 #else
2989 gdk_device_ungrab(gdk_device_manager_get_client_pointer(manager), GDK_CURRENT_TIME); 3028 gdk_device_ungrab(gdk_device_manager_get_client_pointer(manager), GDK_CURRENT_TIME);
2990 manager = NULL; 3029 manager = NULL;
3030 #endif
2991 DW_MUTEX_UNLOCK; 3031 DW_MUTEX_UNLOCK;
2992 } 3032 }
2993 3033
2994 /* 3034 /*
2995 * Create a new Window Frame. 3035 * Create a new Window Frame.
3643 return; 3683 return;
3644 3684
3645 popup = parent; 3685 popup = parent;
3646 3686
3647 DW_MUTEX_LOCK; 3687 DW_MUTEX_LOCK;
3688 #if GTK_CHECK_VERSION(3,22,0)
3689 GdkRectangle rc = { x, y, 1, 1 };
3690 gtk_menu_popup_at_rect(GTK_MENU(*menu), gtk_widget_get_window(parent),
3691 &rc, GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER, NULL);
3692 #else
3648 gtk_menu_popup(GTK_MENU(*menu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME); 3693 gtk_menu_popup(GTK_MENU(*menu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME);
3694 #endif
3649 *menu = NULL; 3695 *menu = NULL;
3650 DW_MUTEX_UNLOCK; 3696 DW_MUTEX_UNLOCK;
3651 } 3697 }
3652 3698
3653 3699
3661 { 3707 {
3662 GdkModifierType state = 0; 3708 GdkModifierType state = 0;
3663 int gx, gy; 3709 int gx, gy;
3664 int _locked_by_me = FALSE; 3710 int _locked_by_me = FALSE;
3665 GdkDisplay *display; 3711 GdkDisplay *display;
3712 GdkDevice *device;
3713 #if GTK_CHECK_VERSION(3,20,0)
3714 GdkSeat *seat;
3715 #else
3666 GdkDeviceManager *manager; 3716 GdkDeviceManager *manager;
3717 #endif
3667 3718
3668 DW_MUTEX_LOCK; 3719 DW_MUTEX_LOCK;
3669 #ifdef GDK_WINDOWING_X11 3720 #ifdef GDK_WINDOWING_X11
3670 display = gdk_display_get_default(); 3721 display = gdk_display_get_default();
3722 #if GTK_CHECK_VERSION(3,20,0)
3723 seat = gdk_display_get_default_seat(display);
3724 device = gdk_seat_get_pointer(seat);
3725 #else
3671 manager = gdk_display_get_device_manager(display); 3726 manager = gdk_display_get_device_manager(display);
3672 gdk_window_get_device_position (gdk_x11_window_lookup_for_display(display, GDK_ROOT_WINDOW()), 3727 device = gdk_device_manager_get_client_pointer(manager);
3673 gdk_device_manager_get_client_pointer(manager), &gx, &gy, &state); 3728 #endif
3729 gdk_window_get_device_position(gdk_x11_window_lookup_for_display(display, GDK_ROOT_WINDOW()),
3730 device, &gx, &gy, &state);
3674 #endif 3731 #endif
3675 if(x) 3732 if(x)
3676 *x = gx; 3733 *x = gx;
3677 if(y) 3734 if(y)
3678 *y = gy; 3735 *y = gy;
3687 */ 3744 */
3688 void dw_pointer_set_pos(long x, long y) 3745 void dw_pointer_set_pos(long x, long y)
3689 { 3746 {
3690 int _locked_by_me = FALSE; 3747 int _locked_by_me = FALSE;
3691 GdkDisplay *display; 3748 GdkDisplay *display;
3749 GdkDevice *device;
3750 #if GTK_CHECK_VERSION(3,20,0)
3751 GdkSeat *seat;
3752 #else
3692 GdkDeviceManager *manager; 3753 GdkDeviceManager *manager;
3754 #endif
3693 3755
3694 DW_MUTEX_LOCK; 3756 DW_MUTEX_LOCK;
3695 #ifdef GDK_WINDOWING_X11 3757 #ifdef GDK_WINDOWING_X11
3696 display = gdk_display_get_default(); 3758 display = gdk_display_get_default();
3759 #if GTK_CHECK_VERSION(3,20,0)
3760 seat = gdk_display_get_default_seat(display);
3761 device = gdk_seat_get_pointer(seat);
3762 #else
3697 manager = gdk_display_get_device_manager(display); 3763 manager = gdk_display_get_device_manager(display);
3698 gdk_device_warp( gdk_device_manager_get_client_pointer(manager), gdk_screen_get_default(), x, y ); 3764 device = gdk_device_manager_get_client_pointer(manager);
3765 #endif
3766 gdk_device_warp(device, gdk_screen_get_default(), x, y);
3699 #endif 3767 #endif
3700 DW_MUTEX_UNLOCK; 3768 DW_MUTEX_UNLOCK;
3701 } 3769 }
3702 3770
3703 #define _DW_TREE_CONTAINER 1 3771 #define _DW_TREE_CONTAINER 1
7100 */ 7168 */
7101 void dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) 7169 void dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y)
7102 { 7170 {
7103 int _locked_by_me = FALSE; 7171 int _locked_by_me = FALSE;
7104 cairo_t *cr = NULL; 7172 cairo_t *cr = NULL;
7173 #if GTK_CHECK_VERSION(3,22,0)
7174 GdkDrawingContext *dc = NULL;
7175 #endif
7105 7176
7106 DW_MUTEX_LOCK; 7177 DW_MUTEX_LOCK;
7107 if(handle) 7178 if(handle)
7108 { 7179 {
7109 GdkWindow *window = gtk_widget_get_window(handle); 7180 GdkWindow *window = gtk_widget_get_window(handle);
7111 if(!window || !GDK_IS_WINDOW(window)) 7182 if(!window || !GDK_IS_WINDOW(window))
7112 { 7183 {
7113 DW_MUTEX_UNLOCK; 7184 DW_MUTEX_UNLOCK;
7114 return; 7185 return;
7115 } 7186 }
7187 #if GTK_CHECK_VERSION(3,22,0)
7188 dc = gdk_window_begin_draw_frame(window, NULL);
7189 cr = gdk_drawing_context_get_cairo_context(dc);
7190 #else
7116 cr = gdk_cairo_create(window); 7191 cr = gdk_cairo_create(window);
7192 #endif
7117 } 7193 }
7118 else if(pixmap) 7194 else if(pixmap)
7119 cr = cairo_create(pixmap->image); 7195 cr = cairo_create(pixmap->image);
7120 if(cr) 7196 if(cr)
7121 { 7197 {
7123 7199
7124 gdk_cairo_set_source_rgba(cr, foreground); 7200 gdk_cairo_set_source_rgba(cr, foreground);
7125 cairo_set_line_width(cr, 1); 7201 cairo_set_line_width(cr, 1);
7126 cairo_move_to(cr, x, y); 7202 cairo_move_to(cr, x, y);
7127 cairo_stroke(cr); 7203 cairo_stroke(cr);
7204 #if GTK_CHECK_VERSION(3,22,0)
7205 /* If we are using a drawing context...
7206 * we don't own the cairo context so don't destroy it.
7207 */
7208 if(!dc)
7209 #endif
7128 cairo_destroy(cr); 7210 cairo_destroy(cr);
7129 } 7211 }
7130 DW_MUTEX_UNLOCK; 7212 DW_MUTEX_UNLOCK;
7131 } 7213 }
7132 7214
7141 */ 7223 */
7142 void dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) 7224 void dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2)
7143 { 7225 {
7144 int _locked_by_me = FALSE; 7226 int _locked_by_me = FALSE;
7145 cairo_t *cr = NULL; 7227 cairo_t *cr = NULL;
7228 #if GTK_CHECK_VERSION(3,22,0)
7229 GdkDrawingContext *dc = NULL;
7230 #endif
7146 7231
7147 DW_MUTEX_LOCK; 7232 DW_MUTEX_LOCK;
7148 if(handle) 7233 if(handle)
7149 { 7234 {
7150 GdkWindow *window = gtk_widget_get_window(handle); 7235 GdkWindow *window = gtk_widget_get_window(handle);
7152 if(!window || !GDK_IS_WINDOW(window)) 7237 if(!window || !GDK_IS_WINDOW(window))
7153 { 7238 {
7154 DW_MUTEX_UNLOCK; 7239 DW_MUTEX_UNLOCK;
7155 return; 7240 return;
7156 } 7241 }
7242 #if GTK_CHECK_VERSION(3,22,0)
7243 dc = gdk_window_begin_draw_frame(window, NULL);
7244 cr = gdk_drawing_context_get_cairo_context(dc);
7245 #else
7157 cr = gdk_cairo_create(window); 7246 cr = gdk_cairo_create(window);
7247 #endif
7158 } 7248 }
7159 else if(pixmap) 7249 else if(pixmap)
7160 cr = cairo_create(pixmap->image); 7250 cr = cairo_create(pixmap->image);
7161 if(cr) 7251 if(cr)
7162 { 7252 {
7165 gdk_cairo_set_source_rgba(cr, foreground); 7255 gdk_cairo_set_source_rgba(cr, foreground);
7166 cairo_set_line_width(cr, 1); 7256 cairo_set_line_width(cr, 1);
7167 cairo_move_to(cr, x1, y1); 7257 cairo_move_to(cr, x1, y1);
7168 cairo_line_to(cr, x2, y2); 7258 cairo_line_to(cr, x2, y2);
7169 cairo_stroke(cr); 7259 cairo_stroke(cr);
7260 #if GTK_CHECK_VERSION(3,22,0)
7261 /* If we are using a drawing context...
7262 * we don't own the cairo context so don't destroy it.
7263 */
7264 if(!dc)
7265 #endif
7170 cairo_destroy(cr); 7266 cairo_destroy(cr);
7171 } 7267 }
7172 DW_MUTEX_UNLOCK; 7268 DW_MUTEX_UNLOCK;
7173 } 7269 }
7174 7270
7184 void dw_draw_polygon(HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y) 7280 void dw_draw_polygon(HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y)
7185 { 7281 {
7186 int _locked_by_me = FALSE; 7282 int _locked_by_me = FALSE;
7187 cairo_t *cr = NULL; 7283 cairo_t *cr = NULL;
7188 int z; 7284 int z;
7285 #if GTK_CHECK_VERSION(3,22,0)
7286 GdkDrawingContext *dc = NULL;
7287 #endif
7189 7288
7190 DW_MUTEX_LOCK; 7289 DW_MUTEX_LOCK;
7191 if(handle) 7290 if(handle)
7192 { 7291 {
7193 GdkWindow *window = gtk_widget_get_window(handle); 7292 GdkWindow *window = gtk_widget_get_window(handle);
7195 if(!window || !GDK_IS_WINDOW(window)) 7294 if(!window || !GDK_IS_WINDOW(window))
7196 { 7295 {
7197 DW_MUTEX_UNLOCK; 7296 DW_MUTEX_UNLOCK;
7198 return; 7297 return;
7199 } 7298 }
7299 #if GTK_CHECK_VERSION(3,22,0)
7300 dc = gdk_window_begin_draw_frame(window, NULL);
7301 cr = gdk_drawing_context_get_cairo_context(dc);
7302 #else
7200 cr = gdk_cairo_create(window); 7303 cr = gdk_cairo_create(window);
7304 #endif
7201 } 7305 }
7202 else if(pixmap) 7306 else if(pixmap)
7203 cr = cairo_create(pixmap->image); 7307 cr = cairo_create(pixmap->image);
7204 if(cr) 7308 if(cr)
7205 { 7309 {
7216 cairo_line_to(cr, x[z], y[z]); 7320 cairo_line_to(cr, x[z], y[z]);
7217 } 7321 }
7218 if(flags & DW_DRAW_FILL) 7322 if(flags & DW_DRAW_FILL)
7219 cairo_fill(cr); 7323 cairo_fill(cr);
7220 cairo_stroke(cr); 7324 cairo_stroke(cr);
7325 #if GTK_CHECK_VERSION(3,22,0)
7326 /* If we are using a drawing context...
7327 * we don't own the cairo context so don't destroy it.
7328 */
7329 if(!dc)
7330 #endif
7221 cairo_destroy(cr); 7331 cairo_destroy(cr);
7222 } 7332 }
7223 DW_MUTEX_UNLOCK; 7333 DW_MUTEX_UNLOCK;
7224 } 7334 }
7225 7335
7235 */ 7345 */
7236 void dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height) 7346 void dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height)
7237 { 7347 {
7238 int _locked_by_me = FALSE; 7348 int _locked_by_me = FALSE;
7239 cairo_t *cr = NULL; 7349 cairo_t *cr = NULL;
7350 #if GTK_CHECK_VERSION(3,22,0)
7351 GdkDrawingContext *dc = NULL;
7352 #endif
7240 7353
7241 DW_MUTEX_LOCK; 7354 DW_MUTEX_LOCK;
7242 if(handle) 7355 if(handle)
7243 { 7356 {
7244 GdkWindow *window = gtk_widget_get_window(handle); 7357 GdkWindow *window = gtk_widget_get_window(handle);
7246 if(!window || !GDK_IS_WINDOW(window)) 7359 if(!window || !GDK_IS_WINDOW(window))
7247 { 7360 {
7248 DW_MUTEX_UNLOCK; 7361 DW_MUTEX_UNLOCK;
7249 return; 7362 return;
7250 } 7363 }
7364 #if GTK_CHECK_VERSION(3,22,0)
7365 dc = gdk_window_begin_draw_frame(window, NULL);
7366 cr = gdk_drawing_context_get_cairo_context(dc);
7367 #else
7251 cr = gdk_cairo_create(window); 7368 cr = gdk_cairo_create(window);
7369 #endif
7252 } 7370 }
7253 else if(pixmap) 7371 else if(pixmap)
7254 cr = cairo_create(pixmap->image); 7372 cr = cairo_create(pixmap->image);
7255 if(cr) 7373 if(cr)
7256 { 7374 {
7266 cairo_line_to(cr, x + width, y + height); 7384 cairo_line_to(cr, x + width, y + height);
7267 cairo_line_to(cr, x + width, y); 7385 cairo_line_to(cr, x + width, y);
7268 if(flags & DW_DRAW_FILL) 7386 if(flags & DW_DRAW_FILL)
7269 cairo_fill(cr); 7387 cairo_fill(cr);
7270 cairo_stroke(cr); 7388 cairo_stroke(cr);
7389 #if GTK_CHECK_VERSION(3,22,0)
7390 /* If we are using a drawing context...
7391 * we don't own the cairo context so don't destroy it.
7392 */
7393 if(!dc)
7394 #endif
7271 cairo_destroy(cr); 7395 cairo_destroy(cr);
7272 } 7396 }
7273 DW_MUTEX_UNLOCK; 7397 DW_MUTEX_UNLOCK;
7274 } 7398 }
7275 7399
7288 */ 7412 */
7289 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) 7413 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2)
7290 { 7414 {
7291 int _locked_by_me = FALSE; 7415 int _locked_by_me = FALSE;
7292 cairo_t *cr = NULL; 7416 cairo_t *cr = NULL;
7417 #if GTK_CHECK_VERSION(3,22,0)
7418 GdkDrawingContext *dc = NULL;
7419 #endif
7293 7420
7294 DW_MUTEX_LOCK; 7421 DW_MUTEX_LOCK;
7295 if(handle) 7422 if(handle)
7296 { 7423 {
7297 GdkWindow *window = gtk_widget_get_window(handle); 7424 GdkWindow *window = gtk_widget_get_window(handle);
7299 if(!window || !GDK_IS_WINDOW(window)) 7426 if(!window || !GDK_IS_WINDOW(window))
7300 { 7427 {
7301 DW_MUTEX_UNLOCK; 7428 DW_MUTEX_UNLOCK;
7302 return; 7429 return;
7303 } 7430 }
7431 #if GTK_CHECK_VERSION(3,22,0)
7432 dc = gdk_window_begin_draw_frame(window, NULL);
7433 cr = gdk_drawing_context_get_cairo_context(dc);
7434 #else
7304 cr = gdk_cairo_create(window); 7435 cr = gdk_cairo_create(window);
7436 #endif
7305 } 7437 }
7306 else if(pixmap) 7438 else if(pixmap)
7307 cr = cairo_create(pixmap->image); 7439 cr = cairo_create(pixmap->image);
7308 if(cr) 7440 if(cr)
7309 { 7441 {
7331 cairo_arc(cr, xorigin, yorigin, r, a1, a2); 7463 cairo_arc(cr, xorigin, yorigin, r, a1, a2);
7332 } 7464 }
7333 if(flags & DW_DRAW_FILL) 7465 if(flags & DW_DRAW_FILL)
7334 cairo_fill(cr); 7466 cairo_fill(cr);
7335 cairo_stroke(cr); 7467 cairo_stroke(cr);
7468 #if GTK_CHECK_VERSION(3,22,0)
7469 /* If we are using a drawing context...
7470 * we don't own the cairo context so don't destroy it.
7471 */
7472 if(!dc)
7473 #endif
7336 cairo_destroy(cr); 7474 cairo_destroy(cr);
7337 } 7475 }
7338 DW_MUTEX_UNLOCK; 7476 DW_MUTEX_UNLOCK;
7339 } 7477 }
7340 7478
7350 { 7488 {
7351 int _locked_by_me = FALSE; 7489 int _locked_by_me = FALSE;
7352 cairo_t *cr = NULL; 7490 cairo_t *cr = NULL;
7353 PangoFontDescription *font; 7491 PangoFontDescription *font;
7354 char *tmpname, *fontname = "monospace 10"; 7492 char *tmpname, *fontname = "monospace 10";
7493 #if GTK_CHECK_VERSION(3,22,0)
7494 GdkDrawingContext *dc = NULL;
7495 #endif
7355 7496
7356 if(!text) 7497 if(!text)
7357 return; 7498 return;
7358 7499
7359 DW_MUTEX_LOCK; 7500 DW_MUTEX_LOCK;
7364 if(!window || !GDK_IS_WINDOW(window)) 7505 if(!window || !GDK_IS_WINDOW(window))
7365 { 7506 {
7366 DW_MUTEX_UNLOCK; 7507 DW_MUTEX_UNLOCK;
7367 return; 7508 return;
7368 } 7509 }
7510 #if GTK_CHECK_VERSION(3,22,0)
7511 dc = gdk_window_begin_draw_frame(window, NULL);
7512 cr = gdk_drawing_context_get_cairo_context(dc);
7513 #else
7369 cr = gdk_cairo_create(window); 7514 cr = gdk_cairo_create(window);
7515 #endif
7370 if((tmpname = (char *)g_object_get_data(G_OBJECT(handle), "_dw_fontname"))) 7516 if((tmpname = (char *)g_object_get_data(G_OBJECT(handle), "_dw_fontname")))
7371 fontname = tmpname; 7517 fontname = tmpname;
7372 } 7518 }
7373 else if(pixmap) 7519 else if(pixmap)
7374 { 7520 {
7420 } 7566 }
7421 g_object_unref(context); 7567 g_object_unref(context);
7422 } 7568 }
7423 pango_font_description_free(font); 7569 pango_font_description_free(font);
7424 } 7570 }
7571 #if GTK_CHECK_VERSION(3,22,0)
7572 /* If we are using a drawing context...
7573 * we don't own the cairo context so don't destroy it.
7574 */
7575 if(!dc)
7576 #endif
7425 cairo_destroy(cr); 7577 cairo_destroy(cr);
7426 } 7578 }
7427 DW_MUTEX_UNLOCK; 7579 DW_MUTEX_UNLOCK;
7428 } 7580 }
7429 7581
7762 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight) 7914 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight)
7763 { 7915 {
7764 int _locked_by_me = FALSE; 7916 int _locked_by_me = FALSE;
7765 cairo_t *cr = NULL; 7917 cairo_t *cr = NULL;
7766 int retval = DW_ERROR_GENERAL; 7918 int retval = DW_ERROR_GENERAL;
7919 #if GTK_CHECK_VERSION(3,22,0)
7920 GdkDrawingContext *dc = NULL;
7921 #endif
7767 7922
7768 if((!dest && (!destp || !destp->image)) || (!src && (!srcp || !srcp->image))) 7923 if((!dest && (!destp || !destp->image)) || (!src && (!srcp || !srcp->image)))
7769 return retval; 7924 return retval;
7770 7925
7771 DW_MUTEX_LOCK; 7926 DW_MUTEX_LOCK;
7776 if(!window || !GDK_IS_WINDOW(window)) 7931 if(!window || !GDK_IS_WINDOW(window))
7777 { 7932 {
7778 DW_MUTEX_UNLOCK; 7933 DW_MUTEX_UNLOCK;
7779 return retval; 7934 return retval;
7780 } 7935 }
7936 #if GTK_CHECK_VERSION(3,22,0)
7937 dc = gdk_window_begin_draw_frame(window, NULL);
7938 cr = gdk_drawing_context_get_cairo_context(dc);
7939 #else
7781 cr = gdk_cairo_create(window); 7940 cr = gdk_cairo_create(window);
7941 #endif
7782 } 7942 }
7783 else if(destp) 7943 else if(destp)
7784 cr = cairo_create(destp->image); 7944 cr = cairo_create(destp->image);
7785 7945
7786 if(cr) 7946 if(cr)
7799 else if(srcp) 7959 else if(srcp)
7800 cairo_set_source_surface (cr, srcp->image, (xdest + xsrc) / xscale, (ydest + ysrc) / yscale); 7960 cairo_set_source_surface (cr, srcp->image, (xdest + xsrc) / xscale, (ydest + ysrc) / yscale);
7801 7961
7802 cairo_rectangle(cr, xdest / xscale, ydest / yscale, width, height); 7962 cairo_rectangle(cr, xdest / xscale, ydest / yscale, width, height);
7803 cairo_fill(cr); 7963 cairo_fill(cr);
7964 #if GTK_CHECK_VERSION(3,22,0)
7965 /* If we are using a drawing context...
7966 * we don't own the cairo context so don't destroy it.
7967 */
7968 if(!dc)
7969 #endif
7804 cairo_destroy(cr); 7970 cairo_destroy(cr);
7805 retval = DW_ERROR_NONE; 7971 retval = DW_ERROR_NONE;
7806 } 7972 }
7807 DW_MUTEX_UNLOCK; 7973 DW_MUTEX_UNLOCK;
7808 return retval; 7974 return retval;
9344 gtk_widget_get_preferred_height(handle, NULL, height); 9510 gtk_widget_get_preferred_height(handle, NULL, height);
9345 } 9511 }
9346 DW_MUTEX_UNLOCK; 9512 DW_MUTEX_UNLOCK;
9347 } 9513 }
9348 9514
9515 /* Internal version to simplify the code with multiple versions of GTK */
9516 int _dw_screen_width(void)
9517 {
9518 #if GTK_CHECK_VERSION(3,22,0)
9519 {
9520 GdkDisplay *display = gdk_display_get_default();
9521
9522 if(display)
9523 {
9524 GdkMonitor *monitor = gdk_display_get_primary_monitor(display);
9525
9526 if(monitor)
9527 {
9528 GdkRectangle rc = { 0, 0, 0 ,0 };
9529 gdk_monitor_get_geometry(monitor, &rc);
9530 return rc.width;
9531 }
9532 }
9533 }
9534 return 0;
9535 #else
9536 return gdk_screen_width();
9537 #endif
9538 }
9539
9349 /* 9540 /*
9350 * Returns the width of the screen. 9541 * Returns the width of the screen.
9351 */ 9542 */
9352 int dw_screen_width(void) 9543 int dw_screen_width(void)
9353 { 9544 {
9545 int retval = 0;
9546 int _locked_by_me = FALSE;
9547
9548 DW_MUTEX_LOCK;
9549 retval = _dw_screen_width();
9550 DW_MUTEX_UNLOCK;
9551 return retval;
9552 }
9553
9554 /* Internal version to simplify the code with multiple versions of GTK */
9555 int _dw_screen_height(void)
9556 {
9557 #if GTK_CHECK_VERSION(3,22,0)
9558 {
9559 GdkDisplay *display = gdk_display_get_default();
9560
9561 if(display)
9562 {
9563 GdkMonitor *monitor = gdk_display_get_primary_monitor(display);
9564
9565 if(monitor)
9566 {
9567 GdkRectangle rc = { 0, 0, 0 ,0 };
9568 gdk_monitor_get_geometry(monitor, &rc);
9569 return rc.height;
9570 }
9571 }
9572 }
9573 return 0;
9574 #else
9575 return gdk_screen_height();
9576 #endif
9577 }
9578
9579 /*
9580 * Returns the height of the screen.
9581 */
9582 int dw_screen_height(void)
9583 {
9354 int retval; 9584 int retval;
9355 int _locked_by_me = FALSE; 9585 int _locked_by_me = FALSE;
9356 9586
9357 DW_MUTEX_LOCK; 9587 DW_MUTEX_LOCK;
9358 retval = gdk_screen_width(); 9588 retval = _dw_screen_height();
9359 DW_MUTEX_UNLOCK;
9360 return retval;
9361 }
9362
9363 /*
9364 * Returns the height of the screen.
9365 */
9366 int dw_screen_height(void)
9367 {
9368 int retval;
9369 int _locked_by_me = FALSE;
9370
9371 DW_MUTEX_UNLOCK;
9372 retval = gdk_screen_height();
9373 DW_MUTEX_UNLOCK; 9589 DW_MUTEX_UNLOCK;
9374 return retval; 9590 return retval;
9375 } 9591 }
9376 9592
9377 /* This should return the current color depth */ 9593 /* This should return the current color depth */
9379 { 9595 {
9380 int retval; 9596 int retval;
9381 GdkVisual *vis; 9597 GdkVisual *vis;
9382 int _locked_by_me = FALSE; 9598 int _locked_by_me = FALSE;
9383 9599
9384 DW_MUTEX_UNLOCK; 9600 DW_MUTEX_LOCK;
9601 #if GTK_CHECK_VERSION(3,22,0)
9602 vis = gdk_screen_get_system_visual(gdk_screen_get_default());
9603 #else
9385 vis = gdk_visual_get_system(); 9604 vis = gdk_visual_get_system();
9605 #endif
9386 retval = gdk_visual_get_depth(vis); 9606 retval = gdk_visual_get_depth(vis);
9387 DW_MUTEX_UNLOCK; 9607 DW_MUTEX_UNLOCK;
9388 return retval; 9608 return retval;
9389 } 9609 }
9390 9610
9498 /* Do any gravity calculations */ 9718 /* Do any gravity calculations */
9499 if(horz || vert) 9719 if(horz || vert)
9500 { 9720 {
9501 /* Handle horizontal center gravity */ 9721 /* Handle horizontal center gravity */
9502 if((horz & 0xf) == DW_GRAV_CENTER) 9722 if((horz & 0xf) == DW_GRAV_CENTER)
9503 newx += ((gdk_screen_width() / 2) - (width / 2)); 9723 newx += ((_dw_screen_width() / 2) - (width / 2));
9504 /* Handle right gravity */ 9724 /* Handle right gravity */
9505 else if((horz & 0xf) == DW_GRAV_RIGHT) 9725 else if((horz & 0xf) == DW_GRAV_RIGHT)
9506 newx = gdk_screen_width() - width - x; 9726 newx = _dw_screen_width() - width - x;
9507 /* Handle vertical center gravity */ 9727 /* Handle vertical center gravity */
9508 if((vert & 0xf) == DW_GRAV_CENTER) 9728 if((vert & 0xf) == DW_GRAV_CENTER)
9509 newy += ((gdk_screen_height() / 2) - (height / 2)); 9729 newy += ((_dw_screen_height() / 2) - (height / 2));
9510 else if((vert & 0xf) == DW_GRAV_BOTTOM) 9730 else if((vert & 0xf) == DW_GRAV_BOTTOM)
9511 newy = gdk_screen_height() - height - y; 9731 newy = _dw_screen_height() - height - y;
9512 9732
9513 #if GTK_CHECK_VERSION(3,3,8) 9733 #if GTK_CHECK_VERSION(3,3,8)
9514 /* Adjust the values to avoid Gnome bar if requested */ 9734 /* Adjust the values to avoid Gnome bar if requested */
9515 if((horz | vert) & DW_GRAV_OBSTACLES) 9735 if((horz | vert) & DW_GRAV_OBSTACLES)
9516 { 9736 {
9517 GdkRectangle rect; 9737 GdkRectangle rect = { 0, 0, 0, 0 };
9738 #if GTK_CHECK_VERSION(3,22,0)
9739 GdkDisplay *display = gdk_display_get_default();
9740
9741 if(display)
9742 {
9743 GdkMonitor *monitor = gdk_display_get_primary_monitor(display);
9744
9745 if(monitor)
9746 gdk_monitor_get_workarea(monitor, &rect);
9747 }
9748 #else
9518 GdkScreen *screen = gdk_screen_get_default(); 9749 GdkScreen *screen = gdk_screen_get_default();
9519 9750
9520 gdk_screen_get_monitor_workarea(screen, 0, &rect); 9751 gdk_screen_get_monitor_workarea(screen, 0, &rect);
9521 9752 #endif
9522 if(horz & DW_GRAV_OBSTACLES) 9753 if(horz & DW_GRAV_OBSTACLES)
9523 { 9754 {
9524 if((horz & 0xf) == DW_GRAV_LEFT) 9755 if((horz & 0xf) == DW_GRAV_LEFT)
9525 newx += rect.x; 9756 newx += rect.x;
9526 else if((horz & 0xf) == DW_GRAV_RIGHT) 9757 else if((horz & 0xf) == DW_GRAV_RIGHT)
9527 newx -= dw_screen_width() - (rect.x + rect.width); 9758 newx -= _dw_screen_width() - (rect.x + rect.width);
9528 } 9759 }
9529 if(vert & DW_GRAV_OBSTACLES) 9760 if(vert & DW_GRAV_OBSTACLES)
9530 { 9761 {
9531 if((vert & 0xf) == DW_GRAV_TOP) 9762 if((vert & 0xf) == DW_GRAV_TOP)
9532 newy += rect.y; 9763 newy += rect.y;
9533 else if((vert & 0xf) == DW_GRAV_BOTTOM) 9764 else if((vert & 0xf) == DW_GRAV_BOTTOM)
9534 newy -= dw_screen_height() - (rect.y + rect.height); 9765 newy -= _dw_screen_height() - (rect.y + rect.height);
9535 } 9766 }
9536 } 9767 }
9537 #endif 9768 #endif
9538 } 9769 }
9539 /* Finally move the window into place */ 9770 /* Finally move the window into place */