comparison gtk4/dw.c @ 2322:ebcaedfa7ff4

GTK4: Implement dw_pointer_set_pos() with Xlib. Also translate coordinate system in dw_window_get_pos_size().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 17 Feb 2021 05:32:02 +0000
parents 52ca7647f665
children 4b04943319c5
comparison
equal deleted inserted replaced
2321:52ca7647f665 2322:ebcaedfa7ff4
3105 * Sets the X and Y coordinates of the mouse pointer. 3105 * Sets the X and Y coordinates of the mouse pointer.
3106 * Parameters: 3106 * Parameters:
3107 * x: X coordinate. 3107 * x: X coordinate.
3108 * y: Y coordinate. 3108 * y: Y coordinate.
3109 */ 3109 */
3110 #ifndef GDK_WINDOWING_X11
3110 void dw_pointer_set_pos(long x, long y) 3111 void dw_pointer_set_pos(long x, long y)
3111 { 3112 {
3112 /* TODO: See if this is possible in GTK4 */ 3113 }
3113 } 3114 #else
3115 DW_FUNCTION_DEFINITION(dw_pointer_set_pos, void, long x, long y)
3116 DW_FUNCTION_ADD_PARAM2(x, y)
3117 DW_FUNCTION_NO_RETURN(dw_pointer_set_pos)
3118 DW_FUNCTION_RESTORE_PARAM2(x, long, y, long)
3119 {
3120 GdkDisplay *display = gdk_display_get_default();
3121
3122 if(display)
3123 {
3124 Display *xdisplay = gdk_x11_display_get_xdisplay(display);
3125 Window xrootwin = gdk_x11_display_get_xrootwindow(display);
3126
3127 if(xdisplay)
3128 XWarpPointer(xdisplay, None, xrootwin, 0, 0, 0, 0, (int)x, (int)y);
3129 }
3130 DW_FUNCTION_RETURN_NOTHING;
3131 }
3132 #endif
3114 3133
3115 #define _DW_TREE_CONTAINER 1 3134 #define _DW_TREE_CONTAINER 1
3116 #define _DW_TREE_TREE 2 3135 #define _DW_TREE_TREE 2
3117 #define _DW_TREE_LISTBOX 3 3136 #define _DW_TREE_LISTBOX 3
3118 3137
8594 } 8613 }
8595 } 8614 }
8596 DW_FUNCTION_RETURN_NOTHING; 8615 DW_FUNCTION_RETURN_NOTHING;
8597 } 8616 }
8598 #endif 8617 #endif
8618
8599 /* 8619 /*
8600 * Sets the position and size of a given window (widget). 8620 * Sets the position and size of a given window (widget).
8601 * Parameters: 8621 * Parameters:
8602 * handle: Window (widget) handle. 8622 * handle: Window (widget) handle.
8603 * x: X location from the bottom left. 8623 * x: X location from the bottom left.
8649 { 8669 {
8650 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle)); 8670 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
8651 8671
8652 if(surface) 8672 if(surface)
8653 { 8673 {
8674 GdkDisplay *display = gdk_display_get_default();
8654 XWindowAttributes xwa; 8675 XWindowAttributes xwa;
8676 int ix = 0, iy = 0;
8677
8678 if(display)
8679 {
8680 Window child, xrootwin = gdk_x11_display_get_xrootwindow(display);
8681
8682 XTranslateCoordinates(GDK_SURFACE_XDISPLAY(surface), GDK_SURFACE_XID(surface),
8683 xrootwin, 0, 0, &ix, &iy, &child);
8684
8685 }
8655 8686
8656 XGetWindowAttributes(GDK_SURFACE_XDISPLAY(surface), 8687 XGetWindowAttributes(GDK_SURFACE_XDISPLAY(surface),
8657 GDK_SURFACE_XID(surface), &xwa); 8688 GDK_SURFACE_XID(surface), &xwa);
8658 if(x) 8689 if(x)
8659 *x = (long)xwa.x; 8690 *x = (long)(ix - xwa.x);
8660 if(y) 8691 if(y)
8661 *y = (long)xwa.y; 8692 *y = (long)(ix - xwa.y);
8662 } 8693 }
8663 } 8694 }
8664 #else 8695 #else
8665 if(x) 8696 if(x)
8666 *x = 0; 8697 *x = 0;