Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_window.c ewl_window.h ewl_enums.h ewl_menu.c 


Log Message:
Add pointer and mouse grabbing to windows and use in the menu.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_window.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -3 -r1.16 -r1.17
--- ewl_window.c        20 Oct 2005 05:38:08 -0000      1.16
+++ ewl_window.c        24 Oct 2005 04:19:11 -0000      1.17
@@ -28,6 +28,58 @@
 }
 
 /**
+ * @param w: the window to be initialized to default values and callbacks
+ * @return Returns TRUE or FALSE depending on if initialization succeeds.
+ * @brief Initialize a window to default values and callbacks
+ *
+ * Sets the values and callbacks of a window @a w to their defaults.
+ */
+int ewl_window_init(Ewl_Window * w)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("w", w, FALSE);
+
+       /*
+        * Initialize the fields of the inherited container class
+        */
+       ewl_embed_init(EWL_EMBED(w));
+       ewl_widget_appearance_set(EWL_WIDGET(w), "window");
+       ewl_widget_inherit(EWL_WIDGET(w), "window");
+       ewl_object_fill_policy_set(EWL_OBJECT(w), EWL_FLAG_FILL_FILL);
+       w->title = strdup("EWL");
+       w->name = strdup("EWL");
+       w->classname  = strdup("EWL");
+
+       ewl_callback_prepend(EWL_WIDGET(w), EWL_CALLBACK_REALIZE,
+                            ewl_window_realize_cb, NULL);
+       ewl_callback_append(EWL_WIDGET(w), EWL_CALLBACK_REALIZE,
+                            ewl_window_postrealize_cb, NULL);
+       ewl_callback_prepend(EWL_WIDGET(w), EWL_CALLBACK_UNREALIZE,
+                            ewl_window_unrealize_cb, NULL);
+       ewl_callback_append(EWL_WIDGET(w), EWL_CALLBACK_SHOW,
+                           ewl_window_show_cb, NULL);
+       ewl_callback_append(EWL_WIDGET(w), EWL_CALLBACK_EXPOSE,
+                           ewl_window_expose_cb, NULL);
+       ewl_callback_append(EWL_WIDGET(w), EWL_CALLBACK_HIDE,
+                           ewl_window_hide_cb, NULL);
+       ewl_callback_prepend(EWL_WIDGET(w), EWL_CALLBACK_DESTROY,
+                            ewl_window_destroy_cb, NULL);
+       /*
+        * Override the default configure callbacks since the window
+        * has special needs for placement.
+        */
+       ewl_callback_del(EWL_WIDGET(w), EWL_CALLBACK_CONFIGURE,
+                       ewl_overlay_configure_cb);
+       ewl_callback_prepend(EWL_WIDGET(w), EWL_CALLBACK_CONFIGURE,
+                            ewl_window_configure_cb, NULL);
+
+       LAYER(w) = -1000;
+       ecore_list_append(ewl_window_list, w);
+
+       DRETURN_INT(TRUE, DLEVEL_STABLE);
+}
+
+/**
  * @param window: the X window to search for on the list of ewl window's
  * @return Returns the found ewl window on success, NULL on failure.
  * @brief Find an ewl window by it's X window
@@ -349,53 +401,117 @@
 }
 
 /**
- * @param w: the window to be initialized to default values and callbacks
- * @return Returns TRUE or FALSE depending on if initialization succeeds.
- * @brief Initialize a window to default values and callbacks
- *
- * Sets the values and callbacks of a window @a w to their defaults.
+ * @param win: the window to change keyboard grab settings.
+ * @param grab: TRUE or FALSE to indicate grab state.
+ * @return Returns no value.
+ * @brief Changes the keyboard grab state on the specified window.
  */
-int ewl_window_init(Ewl_Window * w)
+void ewl_window_keyboard_grab_set(Ewl_Window *win, int grab)
 {
        DENTER_FUNCTION(DLEVEL_STABLE);
-       DCHECK_PARAM_PTR_RET("w", w, FALSE);
+
+       DCHECK_PARAM_PTR("win", win);
+       DCHECK_TYPE("win", win, "window");
+
+       if (grab) {
+               win->flags |= EWL_WINDOW_GRAB_KEYBOARD;
+       }
+       else {
+               win->flags &= ~EWL_WINDOW_GRAB_KEYBOARD;
+       }
 
        /*
-        * Initialize the fields of the inherited container class
+        * Grab the keyboard if we're realized.
         */
-       ewl_embed_init(EWL_EMBED(w));
-       ewl_widget_appearance_set(EWL_WIDGET(w), "window");
-       ewl_widget_inherit(EWL_WIDGET(w), "window");
-       ewl_object_fill_policy_set(EWL_OBJECT(w), EWL_FLAG_FILL_FILL);
-       w->title = strdup("EWL");
-       w->name = strdup("EWL");
-       w->classname  = strdup("EWL");
+       if (VISIBLE(win) && win->window) {
+#ifdef ENABLE_EWL_SOFTWARE_X11
+               if (grab)
+                       ecore_x_keyboard_grab((Ecore_X_Window)win->window);
+               else
+                       ecore_x_keyboard_ungrab();
+#endif
+       }
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param win: window to retrieve keyboard grab state
+ * @return Returns TRUE if window is grabbing keyboard, FALSE otherwise.
+ * @brief Retrieves the current keyboard grab state on a window.
+ */
+int ewl_window_keyboard_grab_get(Ewl_Window *win)
+{
+       int grab;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       DCHECK_PARAM_PTR_RET("win", win, FALSE);
+       DCHECK_TYPE_RET("win", win, "window", FALSE);
+
+       if (win->flags & EWL_WINDOW_GRAB_KEYBOARD)
+               grab = TRUE;
+       else
+               grab = FALSE;
+
+       DRETURN_INT(grab, DLEVEL_STABLE);
+}
+
+/**
+ * @param win: the window to change pointer grab settings.
+ * @param grab: TRUE or FALSE to indicate grab state.
+ * @return Returns no value.
+ * @brief Changes the pointer grab state on the specified window.
+ */
+void ewl_window_pointer_grab_set(Ewl_Window *win, int grab)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       DCHECK_PARAM_PTR("win", win);
+       DCHECK_TYPE("win", win, "window");
+
+       if (grab) {
+               win->flags |= EWL_WINDOW_GRAB_POINTER;
+       }
+       else {
+               win->flags &= ~EWL_WINDOW_GRAB_POINTER;
+       }
 
-       ewl_callback_prepend(EWL_WIDGET(w), EWL_CALLBACK_REALIZE,
-                            ewl_window_realize_cb, NULL);
-       ewl_callback_append(EWL_WIDGET(w), EWL_CALLBACK_REALIZE,
-                            ewl_window_postrealize_cb, NULL);
-       ewl_callback_prepend(EWL_WIDGET(w), EWL_CALLBACK_UNREALIZE,
-                            ewl_window_unrealize_cb, NULL);
-       ewl_callback_append(EWL_WIDGET(w), EWL_CALLBACK_SHOW,
-                           ewl_window_show_cb, NULL);
-       ewl_callback_append(EWL_WIDGET(w), EWL_CALLBACK_HIDE,
-                           ewl_window_hide_cb, NULL);
-       ewl_callback_prepend(EWL_WIDGET(w), EWL_CALLBACK_DESTROY,
-                            ewl_window_destroy_cb, NULL);
        /*
-        * Override the default configure callbacks since the window
-        * has special needs for placement.
+        * Grab the pointer if we're realized.
         */
-       ewl_callback_del(EWL_WIDGET(w), EWL_CALLBACK_CONFIGURE,
-                       ewl_overlay_configure_cb);
-       ewl_callback_prepend(EWL_WIDGET(w), EWL_CALLBACK_CONFIGURE,
-                            ewl_window_configure_cb, NULL);
+       if (VISIBLE(win) && win->window) {
+#ifdef ENABLE_EWL_SOFTWARE_X11
+               if (grab)
+                       ecore_x_pointer_grab((Ecore_X_Window)win->window);
+               else
+                       ecore_x_pointer_ungrab();
+#endif
+       }
 
-       LAYER(w) = -1000;
-       ecore_list_append(ewl_window_list, w);
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
 
-       DRETURN_INT(TRUE, DLEVEL_STABLE);
+/**
+ * @param win: window to retrieve pointer grab state
+ * @return Returns TRUE if window is grabbing pointer, FALSE otherwise.
+ * @brief Retrieves the current pointer grab state on a window.
+ */
+int ewl_window_pointer_grab_get(Ewl_Window *win)
+{
+       int grab;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       DCHECK_PARAM_PTR_RET("win", win, FALSE);
+       DCHECK_TYPE_RET("win", win, "window", FALSE);
+
+       if (win->flags & EWL_WINDOW_GRAB_POINTER)
+               grab = TRUE;
+       else
+               grab = FALSE;
+
+       DRETURN_INT(grab, DLEVEL_STABLE);
 }
 
 void ewl_window_realize_cb(Ewl_Widget * w, void *ev_data __UNUSED__,
@@ -664,22 +780,61 @@
 
                ecore_x_window_show((Ecore_X_Window)win->window);
                ecore_x_window_show((Ecore_X_Window)EWL_EMBED(w)->evas_window);
+
        }
 #endif
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
+void ewl_window_expose_cb(Ewl_Widget *w, void *ev, void *user_data)
+{
+       Ewl_Window *win = EWL_WINDOW(w);
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       if (win->flags & EWL_WINDOW_GRAB_KEYBOARD) {
+               ecore_x_keyboard_grab((Ecore_X_Window)win->window);
+               printf("Grabbed keyboard\n");
+       }
+       if (win->flags & EWL_WINDOW_GRAB_POINTER) {
+               int grabval;
+               grabval = ecore_x_pointer_grab((Ecore_X_Window)win->window);
+               if (grabval == GrabNotViewable)
+                       printf("GrabNotViewable\n");
+               else if (grabval == AlreadyGrabbed)
+                       printf("AlreadyGrabbed\n");
+               else if (grabval == GrabFrozen)
+                       printf("GrabFrozen\n");
+               else if (grabval == GrabInvalidTime)
+                       printf("GrabInvalidTime\n");
+               else
+                       printf("Grabbed pointer\n");
+       }
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
 void ewl_window_hide_cb(Ewl_Widget * widget, void *ev_data __UNUSED__,
                                                void *user_data __UNUSED__)
 {
+       Ewl_Window *win = EWL_WINDOW(widget);
+
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("widget", widget);
 
 #ifdef ENABLE_EWL_SOFTWARE_X11
        if (strstr(EWL_WINDOW(widget)->render, "x11")) {
-               
ecore_x_window_hide((Ecore_X_Window)EWL_EMBED(widget)->evas_window);
-               ecore_x_window_hide((Ecore_X_Window)EWL_WINDOW(widget)->window);
+               
ecore_x_window_hide((Ecore_X_Window)EWL_EMBED(win)->evas_window);
+               ecore_x_window_hide((Ecore_X_Window)win->window);
+               if (win->flags & EWL_WINDOW_GRAB_KEYBOARD) {
+                       ecore_x_keyboard_ungrab();
+                       printf("Ungrabbed keyboard\n");
+               }
+               if (win->flags & EWL_WINDOW_GRAB_POINTER) {
+                       ecore_x_pointer_ungrab();
+                       printf("Ungrabbed pointer\n");
+               }
        }
 #endif
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_window.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ewl_window.h        10 Apr 2005 05:02:17 -0000      1.3
+++ ewl_window.h        24 Oct 2005 04:19:11 -0000      1.4
@@ -67,6 +67,10 @@
 void            ewl_window_raise(Ewl_Window * win);
 void            ewl_window_lower(Ewl_Window * win);
 void            ewl_window_transient_for(Ewl_Window * win, Ewl_Window * 
forwin);
+void            ewl_window_keyboard_grab_set(Ewl_Window *win, int grab);
+int             ewl_window_keyboard_grab_get(Ewl_Window *win);
+void            ewl_window_pointer_grab_set(Ewl_Window *win, int grab);
+int             ewl_window_pointer_grab_get(Ewl_Window *win);
 
 /*
  * Internally used callbacks, override at your own risk.
@@ -81,6 +85,7 @@
                                     void *user_data);
 void            ewl_window_show_cb(Ewl_Widget * w, void *ev_data,
                                  void *user_data);
+void            ewl_window_expose_cb(Ewl_Widget *w, void *ev, void *user_data);
 void            ewl_window_hide_cb(Ewl_Widget * w, void *ev_data,
                                  void *user_data);
 void            ewl_window_destroy_cb(Ewl_Widget * w, void *ev_data,
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_enums.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- ewl_enums.h 24 Oct 2005 02:52:07 -0000      1.17
+++ ewl_enums.h 24 Oct 2005 04:19:11 -0000      1.18
@@ -198,7 +198,9 @@
 enum Ewl_Window_Flags
 {
        EWL_WINDOW_BORDERLESS = 1,
-       EWL_WINDOW_USER_CONFIGURE = 2
+       EWL_WINDOW_USER_CONFIGURE = 2,
+       EWL_WINDOW_GRAB_POINTER = 4,
+       EWL_WINDOW_GRAB_KEYBOARD = 8
 };
 
 typedef enum Ewl_Window_Flags Ewl_Window_Flags;
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_menu.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- ewl_menu.c  24 Oct 2005 03:00:59 -0000      1.10
+++ ewl_menu.c  24 Oct 2005 04:19:11 -0000      1.11
@@ -60,6 +60,8 @@
         * Create the popup menu portion of the widget.
         */
        menu->base.popup = ewl_window_new();
+       ewl_window_keyboard_grab_set(EWL_WINDOW(menu->base.popup), TRUE);
+       ewl_window_pointer_grab_set(EWL_WINDOW(menu->base.popup), TRUE);
        ewl_window_borderless_set(EWL_WINDOW(menu->base.popup));
        ewl_widget_internal_set(menu->base.popup, TRUE);
        ewl_widget_layer_set(menu->base.popup, 1000);
@@ -84,6 +86,8 @@
 
        menu = EWL_MENU(w);
 
+       ewl_menu_popup_move_cb(menu->base.popup, NULL, w);
+
        /*
         * Position the popup menu relative to the menu.
         */
@@ -155,5 +159,7 @@
                                EWL_MENU(menu)->popup_x,
                                EWL_MENU(menu)->popup_y + CURRENT_H(menu));
        }
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to