static void mt_main_generate_motion_event (GdkScreen *screen, gint x, gint y) { gdk_error_trap_push (); gdk_display_warp_pointer (gdk_display_get_default (), screen, x, y); gdk_flush (); gdk_error_trap_pop (); }
BOOL SWELL_SetCursorPos(int X, int Y) { #ifdef SWELL_TARGET_GDK gdk_display_warp_pointer(gdk_display_get_default(),gdk_screen_get_default(),X,Y); return true; #else return false; #endif }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ void x_basic_warp_cursor (GtkWidget* widget, gint x, gint y) { GdkScreen *screen; GdkDisplay *display; int window_x, window_y; gdk_window_get_origin (widget->window, &window_x, &window_y); screen = gtk_widget_get_screen (widget); display = gdk_screen_get_display (screen); gdk_display_warp_pointer (display, screen, window_x + x, window_y + y); }
/** * Adjust the mouse pointer so that it appears in the center of the video * window. Mainly used for when we have the mouse grab */ void video_window_center_pointer( main_window_t win ) { GdkDisplay *display = gtk_widget_get_display(win->video); GdkScreen *screen = gtk_widget_get_screen(win->video); int x,y; int width, height; gdk_window_get_origin(win->video->window, &x, &y); gdk_drawable_get_size(GDK_DRAWABLE(win->video->window), &width, &height); x += width / 2; y += height / 2; gdk_display_warp_pointer( display, screen, x, y ); win->mouse_x = width/2; win->mouse_y = height/2; }
int main(int argc, char **argv) { squidge_t squidge; if (argc != 2) { fprintf(stderr, "Usage: squidge logfile\n"); return 1; } file_fd = open(argv[1], O_RDONLY, 0); if (file_fd < 0) { perror("Couldn't open log file"); return 1; } gtk_init(&argc, &argv); init_ui( &squidge ); squidge.follow_bottom = true; inotify_fd = inotify_init(); inotify_add_watch(inotify_fd, argv[1], IN_MODIFY); inotify_io = g_io_channel_unix_new(inotify_fd); g_io_add_watch(inotify_io, G_IO_IN, read_inotify_fd, &squidge); log_io = g_io_channel_unix_new(file_fd); g_io_add_watch(log_io, G_IO_IN, read_log_file, &squidge); log_io_active = true; stdin_io = g_io_channel_unix_new(0); g_io_add_watch(stdin_io, G_IO_IN, read_stdin, &squidge); /* Hide the cursor by making it transparent */ GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(squidge.ui.win)); GdkCursor *cursor; cursor = gdk_cursor_new(GDK_BLANK_CURSOR); gdk_window_set_cursor(gdk_window, cursor); GdkDisplay *display = gdk_display_get_default(); GdkScreen *scr = gdk_screen_get_default(); gdk_display_warp_pointer(display, scr, 1000, 1000); gtk_main(); return 0; }
static void mouse_handler(GtkWidget *w, GdkEvent *event, gpointer data) { video_canvas_t *canvas = (video_canvas_t *)data; if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *bevent = (GdkEventButton*)event; if (_mouse_enabled || lightpen_enabled) { mouse_button(bevent->button-1, TRUE); gtk_lightpen_setbutton(bevent->button, TRUE); } else { if (bevent->button == 1) { ui_menu_update_all_GTK(); gtk_menu_popup(GTK_MENU(left_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); } else if (bevent->button == 3) { ui_menu_update_all_GTK(); gtk_menu_popup(GTK_MENU(right_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); } } } else if (event->type == GDK_BUTTON_RELEASE && (_mouse_enabled || lightpen_enabled)) { GdkEventButton *bevent = (GdkEventButton*)event; mouse_button(bevent->button-1, FALSE); gtk_lightpen_setbutton(bevent->button, FALSE); } else if (event->type == GDK_MOTION_NOTIFY) { GdkEventMotion *mevent = (GdkEventMotion*)event; if (_mouse_enabled) { /* handle pointer motion events for mouse emulation */ gint x=0, y=0, w=0, h=0, warp=0; gint xoff=0, yoff=0; gint ptrx, ptry; GdkDisplay *display = NULL; GdkScreen *screen = NULL; /* get default display and screen */ display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); /* get cursor position */ gdk_display_get_pointer (display, NULL, &x, &y, NULL); ptrx = (int)mevent->x; ptry = (int)mevent->y; xoff = x - ptrx; yoff = y - ptry; /* w = canvas->draw_buffer->canvas_physical_width; */ w = gtk_widget_get_allocated_width(canvas->emuwindow); h = canvas->draw_buffer->canvas_physical_height; /* DBG(("ptrx:%d ptry:%d x:%d y:%d w:%d h:%d", ptrx, ptry, x, y, w, h)); */ if (mouse_warpx == 1) { /* from left to right */ if ((ptrx > mouse_lasteventx) && (ptrx >= (w - (MOUSE_WRAP_MARGIN * 2))) && (ptrx <= (w - MOUSE_WRAP_MARGIN))) { mouse_warpx = 0; mouse_lasteventx = ptrx; } } else if (mouse_warpx == 2) { /* from right to left */ if ((ptrx < mouse_lasteventx) && (ptrx <= (MOUSE_WRAP_MARGIN * 2)) && (ptrx >= MOUSE_WRAP_MARGIN)) { mouse_warpx = 0; mouse_lasteventx = ptrx; } } if (mouse_warpy == 1) { /* from top to bottom */ if ((ptry > mouse_lasteventy) && (ptry >= (h - (MOUSE_WRAP_MARGIN * 2))) && (ptry <= (h - MOUSE_WRAP_MARGIN))) { mouse_warpy = 0; mouse_lasteventy = ptry; } } else if (mouse_warpy == 2) { /* from bottom to top */ if ((ptry < mouse_lasteventy) && (ptry <= (MOUSE_WRAP_MARGIN * 2)) && (ptry >= MOUSE_WRAP_MARGIN)) { mouse_warpy = 0; mouse_lasteventy = ptry; } } if (mouse_warped || mouse_warpx || mouse_warpy) { /* ignore this event, its the result of us having moved the pointer */ /* DBG(("warped!:%d/%d/%d ptrx:%d ptry:%d lastx:%d lasty:%d", mouse_warped, mouse_warpx, mouse_warpy, ptrx, ptry, mouse_lasteventx, mouse_lasteventy)); */ if (mouse_warped) { --mouse_warped; } } else { if (ptrx < MOUSE_WRAP_MARGIN) { /* from left to right */ mouse_lasteventx = ptrx; ptrx = w - (MOUSE_WRAP_MARGIN + 10); mouse_warpx = 1; warp = 1; } else if (ptrx > (w - MOUSE_WRAP_MARGIN)) { /* from right to left */ mouse_lasteventx = ptrx; ptrx = (MOUSE_WRAP_MARGIN + 10); mouse_warpx = 2; warp = 1; } if (ptry < (MOUSE_WRAP_MARGIN)) { /* from top to bottom */ mouse_lasteventy = ptry; ptry = (h - (MOUSE_WRAP_MARGIN + 10)); mouse_warpy = 1; warp = 1; } else if (ptry > (h - MOUSE_WRAP_MARGIN)) { /* from bottom to top */ mouse_lasteventy = ptry; ptry = (MOUSE_WRAP_MARGIN + 10); mouse_warpy = 2; warp = 1; } /* DBG(("warp:%d ptrx:%d ptry:%d x:%d y:%d w:%d h:%d", warp, ptrx, ptry, x, y, w, h)); */ if (warp) { /* set new cusor position */ ++mouse_warped; /* DBG(("warp to: x:%d y:%d", ptrx, ptry)); */ gdk_display_warp_pointer (display, screen, ptrx + xoff, ptry + yoff); } else { mouse_dx = (ptrx - mouse_lasteventx) / (canvas->videoconfig->doublesizex + 1); mouse_dy = (ptry - mouse_lasteventy) / (canvas->videoconfig->doublesizey + 1); DBG(("mouse move dx:%8d dy:%8d", mouse_dx, mouse_dy)); mouse_move((float)mouse_dx, (float)mouse_dy); mouse_lasteventx = ptrx; mouse_lasteventy = ptry; } } } #ifdef HAVE_FULLSCREEN fullscreen_mouse_moved(canvas, (int)mevent->x, (int)mevent->y, 0); #endif } }
static VALUE rg_warp_pointer(VALUE self, VALUE screen, VALUE x, VALUE y) { gdk_display_warp_pointer(_SELF(self), RVAL2GDKSCREEN(screen), NUM2INT(x), NUM2INT(y)); return self; }
void Sys_SetCursorPos( GtkWindow* window, int x, int y ){ GdkScreen *screen; gdk_display_get_pointer( gdk_display_get_default(), &screen, 0, 0, 0 ); gdk_display_warp_pointer( gdk_display_get_default(), screen, x, y ); }