< prev index next >

modules/javafx.graphics/src/main/native-glass/gtk/glass_general.cpp

Print this page




 486         result = env->NewStringUTF(str->str);
 487         check_and_clear_exception(env);
 488 
 489         g_string_free(str, TRUE);
 490     }
 491     g_strfreev(uris);
 492     return result;
 493 }
 494 
 495 //***************************************************************************
 496 
 497 typedef struct _DeviceGrabContext {
 498     GdkWindow * window;
 499     gboolean grabbed;
 500 } DeviceGrabContext;
 501 
 502 gboolean disableGrab = FALSE;
 503 static gboolean configure_transparent_window(GtkWidget *window);
 504 static void configure_opaque_window(GtkWidget *window);
 505 
 506 static void grab_mouse_device(GdkDevice *device, DeviceGrabContext *context);
 507 static void ungrab_mouse_device(GdkDevice *device);
 508 
 509 gint glass_gdk_visual_get_depth (GdkVisual * visual)
 510 {
 511     // gdk_visual_get_depth is GTK 2.2 +
 512     return gdk_visual_get_depth(visual);
 513 }
 514 
 515 GdkScreen * glass_gdk_window_get_screen(GdkWindow * gdkWindow)
 516 {
 517 #ifdef GLASS_GTK3
 518         GdkVisual * gdkVisual = gdk_window_get_visual(gdkWindow);
 519         return gdk_visual_get_screen(gdkVisual);
 520 #else
 521         return gdk_window_get_screen(gdkWindow);
 522 #endif
 523 }
 524 
 525 gboolean
 526 glass_gdk_mouse_devices_grab(GdkWindow *gdkWindow) {
 527 #ifdef GLASS_GTK3
 528         if (disableGrab) {
 529             return TRUE;
 530         }
 531         DeviceGrabContext context;
 532         GList *devices = gdk_device_manager_list_devices (
 533                              gdk_display_get_device_manager(
 534                                  gdk_display_get_default()),
 535                                  GDK_DEVICE_TYPE_MASTER);
 536 
 537         context.window = gdkWindow;
 538         context.grabbed = FALSE;
 539         g_list_foreach(devices, (GFunc) grab_mouse_device, &context);
 540 
 541         return context.grabbed;
 542 #else
 543     return glass_gdk_mouse_devices_grab_with_cursor(gdkWindow, NULL, TRUE);
 544 #endif
 545 }
 546 
 547 gboolean
 548 glass_gdk_mouse_devices_grab_with_cursor(GdkWindow *gdkWindow, GdkCursor *cursor, gboolean owner_events) {
 549     if (disableGrab) {
 550         return TRUE;
 551     }
 552     GdkGrabStatus status = gdk_pointer_grab(gdkWindow, owner_events, (GdkEventMask)
 553                                             (GDK_POINTER_MOTION_MASK
 554                                                 | GDK_POINTER_MOTION_HINT_MASK
 555                                                 | GDK_BUTTON_MOTION_MASK
 556                                                 | GDK_BUTTON1_MOTION_MASK
 557                                                 | GDK_BUTTON2_MOTION_MASK
 558                                                 | GDK_BUTTON3_MOTION_MASK
 559                                                 | GDK_BUTTON_PRESS_MASK
 560                                                 | GDK_BUTTON_RELEASE_MASK),
 561                                             NULL, cursor, GDK_CURRENT_TIME);
 562 
 563     return (status == GDK_GRAB_SUCCESS) ? TRUE : FALSE;
 564 }
 565 
 566 void
 567 glass_gdk_mouse_devices_ungrab() {
 568 #ifdef GLASS_GTK3
 569         GList *devices = gdk_device_manager_list_devices(
 570                              gdk_display_get_device_manager(
 571                                  gdk_display_get_default()),
 572                                  GDK_DEVICE_TYPE_MASTER);
 573         g_list_foreach(devices, (GFunc) ungrab_mouse_device, NULL);
 574 #else
 575         gdk_pointer_ungrab(GDK_CURRENT_TIME);
 576 #endif
 577 }
 578 
 579 void
 580 glass_gdk_master_pointer_grab(GdkWindow *window, GdkCursor *cursor) {
 581     if (disableGrab) {
 582         gdk_window_set_cursor(window, cursor);
 583         return;
 584     }
 585 #ifdef GLASS_GTK3
 586         gdk_device_grab(gdk_device_manager_get_client_pointer(
 587                     gdk_display_get_device_manager(
 588                         gdk_display_get_default())),
 589                     window, GDK_OWNERSHIP_NONE, FALSE, GDK_ALL_EVENTS_MASK,
 590                     cursor, GDK_CURRENT_TIME);
 591 #else
 592         gdk_pointer_grab(window, FALSE, (GdkEventMask)
 593                          (GDK_POINTER_MOTION_MASK
 594                              | GDK_BUTTON_MOTION_MASK
 595                              | GDK_BUTTON1_MOTION_MASK
 596                              | GDK_BUTTON2_MOTION_MASK


 733                           gdk_screen_get_system_visual(
 734                               gdk_screen_get_default()));
 735   */
 736 }
 737 
 738 gboolean
 739 glass_configure_window_transparency(GtkWidget *window, gboolean transparent) {
 740     if (transparent) {
 741         if (configure_transparent_window(window)) {
 742             return TRUE;
 743         }
 744 
 745         fprintf(stderr,"Can't create transparent stage, because your screen doesn't"
 746                " support alpha channel."
 747                " You need to enable XComposite extension.\n");
 748         fflush(stderr);
 749     }
 750 
 751     configure_opaque_window(window);
 752     return FALSE;
 753 }
 754 
 755 static void
 756 grab_mouse_device(GdkDevice *device, DeviceGrabContext *context) {
 757     GdkInputSource source = gdk_device_get_source(device);
 758     if (source == GDK_SOURCE_MOUSE) {
 759 #ifdef GLASS_GTK3
 760         GdkGrabStatus status = gdk_device_grab(device,
 761                                                context->window,
 762                                                GDK_OWNERSHIP_NONE,
 763                                                TRUE,
 764                                                GDK_ALL_EVENTS_MASK,
 765                                                NULL,
 766                                                GDK_CURRENT_TIME);
 767 #else
 768         GdkGrabStatus status = GDK_GRAB_SUCCESS;
 769 /* FIXME reachable by 2?
 770         GdkGrabStatus status = gdk_device_grab(device,
 771                                                context->window,
 772                                                GDK_OWNERSHIP_NONE,
 773                                                TRUE,
 774                                                GDK_ALL_EVENTS_MASK,
 775                                                NULL,
 776                                                GDK_CURRENT_TIME);
 777                                        */
 778 #endif
 779         if (status == GDK_GRAB_SUCCESS) {
 780             context->grabbed = TRUE;
 781         }
 782     }
 783 }
 784 
 785 static void
 786 ungrab_mouse_device(GdkDevice *device) {
 787 #ifdef GLASS_GTK3
 788     GdkInputSource source = gdk_device_get_source(device);
 789     if (source == GDK_SOURCE_MOUSE) {
 790         gdk_device_ungrab(device, GDK_CURRENT_TIME);
 791     }
 792 #else
 793     (void) device;
 794     // not used on the GTK2 path
 795 #endif
 796 }
 797 
 798 GdkPixbuf *
 799 glass_pixbuf_from_window(GdkWindow *window,
 800     gint srcx, gint srcy,
 801     gint width, gint height)
 802 {
 803     GdkPixbuf * ret = NULL;
 804 
 805 #ifdef GLASS_GTK3
 806         ret = gdk_pixbuf_get_from_window (window, srcx, srcy, width, height);
 807 #else
 808         ret = gdk_pixbuf_get_from_drawable (NULL,
 809             window,
 810             NULL,
 811             srcx, srcy,
 812             0, 0,
 813             width, height);
 814 #endif
 815     return ret;




 486         result = env->NewStringUTF(str->str);
 487         check_and_clear_exception(env);
 488 
 489         g_string_free(str, TRUE);
 490     }
 491     g_strfreev(uris);
 492     return result;
 493 }
 494 
 495 //***************************************************************************
 496 
 497 typedef struct _DeviceGrabContext {
 498     GdkWindow * window;
 499     gboolean grabbed;
 500 } DeviceGrabContext;
 501 
 502 gboolean disableGrab = FALSE;
 503 static gboolean configure_transparent_window(GtkWidget *window);
 504 static void configure_opaque_window(GtkWidget *window);
 505 



 506 gint glass_gdk_visual_get_depth (GdkVisual * visual)
 507 {
 508     // gdk_visual_get_depth is GTK 2.2 +
 509     return gdk_visual_get_depth(visual);
 510 }
 511 
 512 GdkScreen * glass_gdk_window_get_screen(GdkWindow * gdkWindow)
 513 {
 514 #ifdef GLASS_GTK3
 515         GdkVisual * gdkVisual = gdk_window_get_visual(gdkWindow);
 516         return gdk_visual_get_screen(gdkVisual);
 517 #else
 518         return gdk_window_get_screen(gdkWindow);
 519 #endif
 520 }
 521 
 522 gboolean
 523 glass_gdk_mouse_devices_grab(GdkWindow *gdkWindow) {
















 524     return glass_gdk_mouse_devices_grab_with_cursor(gdkWindow, NULL, TRUE);

 525 }
 526 
 527 gboolean
 528 glass_gdk_mouse_devices_grab_with_cursor(GdkWindow *gdkWindow, GdkCursor *cursor, gboolean owner_events) {
 529     if (disableGrab) {
 530         return TRUE;
 531     }
 532     GdkGrabStatus status = gdk_pointer_grab(gdkWindow, owner_events, (GdkEventMask)
 533                                             (GDK_POINTER_MOTION_MASK
 534                                                 | GDK_POINTER_MOTION_HINT_MASK
 535                                                 | GDK_BUTTON_MOTION_MASK
 536                                                 | GDK_BUTTON1_MOTION_MASK
 537                                                 | GDK_BUTTON2_MOTION_MASK
 538                                                 | GDK_BUTTON3_MOTION_MASK
 539                                                 | GDK_BUTTON_PRESS_MASK
 540                                                 | GDK_BUTTON_RELEASE_MASK),
 541                                             NULL, cursor, GDK_CURRENT_TIME);
 542 
 543     return (status == GDK_GRAB_SUCCESS) ? TRUE : FALSE;
 544 }
 545 
 546 void
 547 glass_gdk_mouse_devices_ungrab() {







 548     gdk_pointer_ungrab(GDK_CURRENT_TIME);

 549 }
 550 
 551 void
 552 glass_gdk_master_pointer_grab(GdkWindow *window, GdkCursor *cursor) {
 553     if (disableGrab) {
 554         gdk_window_set_cursor(window, cursor);
 555         return;
 556     }
 557 #ifdef GLASS_GTK3
 558         gdk_device_grab(gdk_device_manager_get_client_pointer(
 559                     gdk_display_get_device_manager(
 560                         gdk_display_get_default())),
 561                     window, GDK_OWNERSHIP_NONE, FALSE, GDK_ALL_EVENTS_MASK,
 562                     cursor, GDK_CURRENT_TIME);
 563 #else
 564         gdk_pointer_grab(window, FALSE, (GdkEventMask)
 565                          (GDK_POINTER_MOTION_MASK
 566                              | GDK_BUTTON_MOTION_MASK
 567                              | GDK_BUTTON1_MOTION_MASK
 568                              | GDK_BUTTON2_MOTION_MASK


 705                           gdk_screen_get_system_visual(
 706                               gdk_screen_get_default()));
 707   */
 708 }
 709 
 710 gboolean
 711 glass_configure_window_transparency(GtkWidget *window, gboolean transparent) {
 712     if (transparent) {
 713         if (configure_transparent_window(window)) {
 714             return TRUE;
 715         }
 716 
 717         fprintf(stderr,"Can't create transparent stage, because your screen doesn't"
 718                " support alpha channel."
 719                " You need to enable XComposite extension.\n");
 720         fflush(stderr);
 721     }
 722 
 723     configure_opaque_window(window);
 724     return FALSE;











































 725 }
 726 
 727 GdkPixbuf *
 728 glass_pixbuf_from_window(GdkWindow *window,
 729     gint srcx, gint srcy,
 730     gint width, gint height)
 731 {
 732     GdkPixbuf * ret = NULL;
 733 
 734 #ifdef GLASS_GTK3
 735         ret = gdk_pixbuf_get_from_window (window, srcx, srcy, width, height);
 736 #else
 737         ret = gdk_pixbuf_get_from_drawable (NULL,
 738             window,
 739             NULL,
 740             srcx, srcy,
 741             0, 0,
 742             width, height);
 743 #endif
 744     return ret;


< prev index next >