devilhorns pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=109d040e3d4a2ffa7c13d56f0f759974f6c6a231

commit 109d040e3d4a2ffa7c13d56f0f759974f6c6a231
Author: Benjamin Jacobs <[email protected]>
Date:   Mon Jun 6 15:46:00 2016 -0400

    ecore-xcb: Fix XCB to be usable again
    
    Summary:
    Well mostly, it seems there is an issue with multi-key events and
    enlightenment. Let's merge this first before opening a ticket.
    
    Reviewers: devilhorns
    
    Subscribers: cedric, jpeg
    
    Differential Revision: https://phab.enlightenment.org/D4017
    
    @fix
---
 src/lib/ecore_x/xcb/ecore_xcb.c         | 37 ++++++++++++++++++++++-----------
 src/lib/ecore_x/xcb/ecore_xcb_icccm.c   |  6 +++---
 src/lib/ecore_x/xcb/ecore_xcb_private.h |  2 +-
 src/lib/ecore_x/xcb/ecore_xcb_randr.c   | 23 +++++++++++---------
 4 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/src/lib/ecore_x/xcb/ecore_xcb.c b/src/lib/ecore_x/xcb/ecore_xcb.c
index 11306c4..15107fb 100644
--- a/src/lib/ecore_x/xcb/ecore_xcb.c
+++ b/src/lib/ecore_x/xcb/ecore_xcb.c
@@ -33,17 +33,8 @@ double _ecore_xcb_double_click_time = 0.25;
  * Functions that start and shut down the Ecore X Library.
  */
 
-/**
- * Initialize the X display connection to the given display.
- *
- * @param   name Display target name.  If @c NULL, the default display is
- *               assumed.
- * @return  The number of times the library has been initialized without
- *          being shut down.  0 is returned if an error occurs.
- * @ingroup Ecore_X_Init_Group
- */
-EAPI int
-ecore_x_init(const char *name)
+static int
+_ecore_x_init(const char *name, Ecore_X_Display *display)
 {
    char *gl = NULL;
    uint32_t mask, list[1];
@@ -168,7 +159,7 @@ ecore_x_init(const char *name)
 #ifdef EVAS_FRAME_QUEUING
              if (_real_threads) _real_threads();
 #endif
-             _ecore_xcb_display = _real_display(name);
+             _ecore_xcb_display = display ? display : _real_display(name);
              if (!_ecore_xcb_display)
                {
                   ERR("Could not open Display via XLib");
@@ -289,6 +280,28 @@ ecore_x_init(const char *name)
 }
 
 /**
+ * Initialize the X display connection to the given display.
+ *
+ * @param   name Display target name.  If @c NULL, the default display is
+ *               assumed.
+ * @return  The number of times the library has been initialized without
+ *          being shut down.  0 is returned if an error occurs.
+ * @ingroup Ecore_X_Init_Group
+ */
+EAPI int
+ecore_x_init(const char *name)
+{
+   return _ecore_x_init(name, NULL);
+}
+
+EAPI int
+ecore_x_init_from_display(Ecore_X_Display *display)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(display, 0);
+   return _ecore_x_init(NULL, display);
+}
+
+/**
  * Shuts down the Ecore X library.
  *
  * In shutting down the library, the X display connection is terminated
diff --git a/src/lib/ecore_x/xcb/ecore_xcb_icccm.c 
b/src/lib/ecore_x/xcb/ecore_xcb_icccm.c
index 5a36b4e..76d7215 100644
--- a/src/lib/ecore_x/xcb/ecore_xcb_icccm.c
+++ b/src/lib/ecore_x/xcb/ecore_xcb_icccm.c
@@ -302,13 +302,13 @@ ecore_x_icccm_name_class_set(Ecore_X_Window win,
                              const char    *class)
 {
    char *class_string, *s;
-   int length_name, length_class;
+   int length_name, length_class = 0;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
    CHECK_XCB_CONN;
 
-   length_name = strlen(name);
-   length_class = strlen(class);
+   if (name) length_name = strlen(name);
+   if (class) length_class = strlen(class);
    class_string =
      (char *)malloc(sizeof(char) * (length_name + length_class + 2));
    if (!class_string) return;
diff --git a/src/lib/ecore_x/xcb/ecore_xcb_private.h 
b/src/lib/ecore_x/xcb/ecore_xcb_private.h
index d6bb743..f56ecac 100644
--- a/src/lib/ecore_x/xcb/ecore_xcb_private.h
+++ b/src/lib/ecore_x/xcb/ecore_xcb_private.h
@@ -75,7 +75,7 @@ extern int _ecore_xcb_log_dom;
 
 #define CHECK_XCB_CONN                              \
   {                                                 \
-     if (xcb_connection_has_error(_ecore_xcb_conn)) \
+     if (!_ecore_xcb_conn || xcb_connection_has_error(_ecore_xcb_conn)) \
        {                                            \
           DBG("XCB Connection Has Error !!");       \
           _ecore_xcb_io_error_handle(NULL);         \
diff --git a/src/lib/ecore_x/xcb/ecore_xcb_randr.c 
b/src/lib/ecore_x/xcb/ecore_xcb_randr.c
index 2b44fc3..74ae2f8 100644
--- a/src/lib/ecore_x/xcb/ecore_xcb_randr.c
+++ b/src/lib/ecore_x/xcb/ecore_xcb_randr.c
@@ -55,6 +55,11 @@
   _ECORE_X_RANDR_EDID_FOR_EACH_DESCRIPTOR_BLOCK(edid, block)                 \
   if ((block[0] == 0) && (block[1] == 0))
 
+#ifdef ECORE_XCB_RANDR
+# define RANDR_VALIDATE_ROOT(screen, root) \
+  ((screen = _ecore_xcb_randr_root_to_screen(root)) != -1)
+#endif
+
 /* local function prototypes */
 static Eina_Bool                                       
_ecore_xcb_randr_output_validate(Ecore_X_Window       root,
                                                                                
         Ecore_X_Randr_Output output);
@@ -189,8 +194,6 @@ _ecore_xcb_randr_root_validate(Ecore_X_Window root 
EINA_UNUSED)
 {
 #ifdef ECORE_XCB_RANDR
    Ecore_X_Randr_Screen scr = -1;
-# define RANDR_VALIDATE_ROOT(screen, root) \
-  ((screen == _ecore_xcb_randr_root_to_screen(root)) != -1)
 #endif
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -2601,8 +2604,6 @@ ecore_x_randr_screen_current_size_get(Ecore_X_Window root,
 #ifdef ECORE_XCB_RANDR
    Ecore_X_Randr_Screen scr = 0;
    xcb_screen_t *s;
-# define RANDR_VALIDATE_ROOT(screen, root) \
-  ((screen == _ecore_xcb_randr_root_to_screen(root)) != -1)
 #endif
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -2647,8 +2648,6 @@ ecore_x_randr_screen_current_size_set(Ecore_X_Window root,
    Ecore_X_Randr_Screen scr;
    int wc = 0, hc = 0, w_mm_c = 0, h_mm_c = 0;
    int mw = 0, mh = 0, xw = 0, xh = 0;
-# define RANDR_VALIDATE_ROOT(screen, root) \
-  ((screen == _ecore_xcb_randr_root_to_screen(root)) != -1)
 #endif
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -4040,14 +4039,16 @@ _ecore_xcb_randr_12_output_name_get(Ecore_X_Window      
 root,
              uint8_t *nbuf;
 
              nbuf = xcb_randr_get_output_info_name(oreply);
-             nbuf += oreply->name_len;
 
              if (len) *len = oreply->name_len;
              if (oreply->name_len > 0)
                {
                   ret = malloc(oreply->name_len + 1);
                   if (ret)
-                    memcpy(ret, nbuf, oreply->name_len + 1);
+                    {
+                       memcpy(ret, nbuf, oreply->name_len + 1);
+                       ret[oreply->name_len] = '\0';
+                    }
                }
 
              free(oreply);
@@ -4083,14 +4084,16 @@ _ecore_xcb_randr_13_output_name_get(Ecore_X_Window      
 root,
              uint8_t *nbuf;
 
              nbuf = xcb_randr_get_output_info_name(oreply);
-             nbuf += oreply->name_len;
 
              if (len) *len = oreply->name_len;
              if (oreply->name_len > 0)
                {
                   ret = malloc(oreply->name_len + 1);
                   if (ret)
-                    memcpy(ret, nbuf, oreply->name_len + 1);
+                    {
+                       memcpy(ret, nbuf, oreply->name_len + 1);
+                       ret[oreply->name_len] = '\0';
+                    }
                }
 
              free(oreply);

-- 


Reply via email to