From a598e6d026548ce7ab580504e05a71a5296b83f0 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 22 Sep 2017 14:58:41 +1200 Subject: Add X11 backend skeleton --- include/wlr/backend/x11.h | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 include/wlr/backend/x11.h (limited to 'include/wlr') diff --git a/include/wlr/backend/x11.h b/include/wlr/backend/x11.h new file mode 100644 index 00000000..28d027c5 --- /dev/null +++ b/include/wlr/backend/x11.h @@ -0,0 +1,11 @@ +#ifndef WLR_BACKEND_X11_H +#define WLR_BACKEND_X11_H + +#include +#include + +struct wlr_backend *wlr_x11_backend_create(const char *display); + +bool wlr_backend_is_x11(struct wlr_backend *backend); + +#endif -- cgit v1.2.3 From 7ad2a57feb4c7e4b191edfbaa68ff3a2fd703f9f Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Fri, 22 Sep 2017 16:00:27 +1200 Subject: Open X11 Window --- backend/backend.c | 2 +- backend/x11/backend.c | 101 +++++++++++++++++++++++++++++++++++++++++++--- include/backend/x11.h | 12 ++++++ include/wlr/backend/x11.h | 6 ++- meson.build | 2 + 5 files changed, 114 insertions(+), 9 deletions(-) (limited to 'include/wlr') diff --git a/backend/backend.c b/backend/backend.c index 21f342ad..ec309da4 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -80,7 +80,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { const char *x11_display = getenv("DISPLAY"); if (x11_display) { - return wlr_x11_backend_create(x11_display); + return wlr_x11_backend_create(display, x11_display); } // Attempt DRM+libinput diff --git a/backend/x11/backend.c b/backend/x11/backend.c index be022a7a..d02bd6eb 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -1,30 +1,119 @@ #include +#include +#include +#include +#include #include #include #include +#include #include "backend/x11.h" -struct wlr_backend *wlr_x11_backend_create(const char *display) { +static struct wlr_backend_impl backend_impl; + +int x11_event(int fd, uint32_t mask, void *data) { + struct wlr_x11_backend *x11 = data; + + xcb_generic_event_t *event = xcb_wait_for_event(x11->xcb_conn); + if (!event) { + return 0; + } + + switch (event->response_type) { + case XCB_EXPOSE: + break; + case XCB_KEY_PRESS: + break; + default: + wlr_log(L_INFO, "Unknown event"); + break; + } + + free(event); + return 0; +} + +struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, + const char *x11_display) { + struct wlr_x11_backend *x11 = calloc(1, sizeof(*x11)); + if (!x11) { + return NULL; + } + + wlr_backend_init(&x11->backend, &backend_impl); + + x11->xlib_conn = XOpenDisplay(x11_display); + if (!x11->xlib_conn) { + wlr_log(L_ERROR, "Failed to open X connection"); + return NULL; + } + + x11->xcb_conn = XGetXCBConnection(x11->xlib_conn); + if (!x11->xcb_conn || xcb_connection_has_error(x11->xcb_conn)) { + wlr_log(L_ERROR, "Failed to open xcb connection"); + goto error; + } + + int fd = xcb_get_file_descriptor(x11->xcb_conn); + struct wl_event_loop *ev = wl_display_get_event_loop(display); + x11->event_source = wl_event_loop_add_fd(ev, fd, WL_EVENT_READABLE, x11_event, x11); + if (!x11->event_source) { + wlr_log(L_ERROR, "Could not create event source"); + goto error; + } + + return &x11->backend; + +error: + xcb_disconnect(x11->xcb_conn); + XCloseDisplay(x11->xlib_conn); + free(x11); return NULL; } static bool wlr_x11_backend_start(struct wlr_backend *backend) { - return false; + struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; + + xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(x11->xcb_conn)).data; + uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; + uint32_t values[2] = { + screen->white_pixel, + XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS + }; + + x11->win = xcb_generate_id(x11->xcb_conn); + + xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, x11->win, screen->root, + 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, + screen->root_visual, mask, values); + + xcb_map_window(x11->xcb_conn, x11->win); + xcb_flush(x11->xcb_conn); + + return true; } static void wlr_x11_backend_destroy(struct wlr_backend *backend) { + if (!backend) { + return; + } + + struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; + + xcb_disconnect(x11->xcb_conn); + free(x11); } struct wlr_egl *wlr_x11_backend_get_egl(struct wlr_backend *backend) { return NULL; } +bool wlr_backend_is_x11(struct wlr_backend *backend) { + return backend->impl == &backend_impl; +} + static struct wlr_backend_impl backend_impl = { .start = wlr_x11_backend_start, .destroy = wlr_x11_backend_destroy, .get_egl = wlr_x11_backend_get_egl, }; - -bool wlr_backend_is_x11(struct wlr_backend *backend) { - return backend->impl == &backend_impl; -} diff --git a/include/backend/x11.h b/include/backend/x11.h index 2f319672..6ef86c8a 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -1,8 +1,20 @@ #ifndef WLR_X11_H #define WLR_X11_H +#include +#include +#include +#include + struct wlr_x11_backend { struct wlr_backend backend; + + Display *xlib_conn; + xcb_connection_t *xcb_conn; + xcb_window_t win; + + struct wlr_egl egl; + struct wl_event_source *event_source; }; #endif diff --git a/include/wlr/backend/x11.h b/include/wlr/backend/x11.h index 28d027c5..3901649b 100644 --- a/include/wlr/backend/x11.h +++ b/include/wlr/backend/x11.h @@ -1,10 +1,12 @@ #ifndef WLR_BACKEND_X11_H #define WLR_BACKEND_X11_H -#include #include +#include +#include -struct wlr_backend *wlr_x11_backend_create(const char *display); +struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, + const char *x11_display); bool wlr_backend_is_x11(struct wlr_backend *backend); diff --git a/meson.build b/meson.build index c0fb50e1..520eceb9 100644 --- a/meson.build +++ b/meson.build @@ -45,6 +45,7 @@ udev = dependency('libudev') pixman = dependency('pixman-1') xcb = dependency('xcb') xcb_composite = dependency('xcb-composite') +x11_xcb = dependency('x11-xcb') libcap = dependency('libcap', required: false) systemd = dependency('libsystemd', required: false) elogind = dependency('libelogind', required: false) @@ -85,6 +86,7 @@ wlr_deps = [ pixman, xcb, xcb_composite, + x11_xcb, libcap, systemd, math, -- cgit v1.2.3 From 517ba0bc168d9968891e8ec0ca595e26ced535bf Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Tue, 26 Sep 2017 14:57:23 +1300 Subject: Change egl_get_config to always use visual id --- backend/drm/drm.c | 3 ++- backend/wayland/backend.c | 3 ++- include/wlr/egl.h | 2 +- render/egl.c | 23 +++++++---------------- 4 files changed, 12 insertions(+), 19 deletions(-) (limited to 'include/wlr') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 8e70e528..1a656172 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -182,7 +182,8 @@ bool wlr_drm_renderer_init(struct wlr_drm_renderer *renderer, int fd) { return false; } - if (!wlr_egl_init(&renderer->egl, EGL_PLATFORM_GBM_MESA, renderer->gbm)) { + if (!wlr_egl_init(&renderer->egl, EGL_PLATFORM_GBM_MESA, + GBM_FORMAT_ARGB8888, renderer->gbm)) { gbm_device_destroy(renderer->gbm); return false; } diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 264ce338..e57f3583 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -42,6 +42,7 @@ static bool wlr_wl_backend_start(struct wlr_backend *_backend) { } backend->started = true; + for (size_t i = 0; i < backend->requested_outputs; ++i) { wlr_wl_output_create(&backend->backend); } @@ -145,7 +146,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { return false; } - wlr_egl_init(&backend->egl, EGL_PLATFORM_WAYLAND_EXT, backend->remote_display); + wlr_egl_init(&backend->egl, EGL_PLATFORM_WAYLAND_EXT, WL_SHM_FORMAT_ARGB8888, backend->remote_display); wlr_egl_bind_display(&backend->egl, backend->local_display); return &backend->backend; diff --git a/include/wlr/egl.h b/include/wlr/egl.h index b37317a5..25329175 100644 --- a/include/wlr/egl.h +++ b/include/wlr/egl.h @@ -30,7 +30,7 @@ struct wlr_egl { * Initializes an egl context for the given platform and remote display. * Will attempt to load all possibly required api functions. */ -bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *display); +bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, EGLint visual_id, void *display); /** * Frees all related egl resources, makes the context not-current and diff --git a/render/egl.c b/render/egl.c index 048626ba..82dea50c 100644 --- a/render/egl.c +++ b/render/egl.c @@ -1,7 +1,6 @@ #include #include #include -#include // GBM_FORMAT_XRGB8888 #include #include #include @@ -68,7 +67,7 @@ static bool egl_exts(struct wlr_egl *egl) { return true; } -static bool egl_get_config(EGLDisplay disp, EGLConfig *out, EGLenum platform) { +static bool egl_get_config(EGLDisplay disp, EGLConfig *out, EGLint visual_id) { EGLint count = 0, matched = 0, ret; ret = eglGetConfigs(disp, NULL, 0, &count); @@ -86,21 +85,13 @@ static bool egl_get_config(EGLDisplay disp, EGLConfig *out, EGLenum platform) { } for (int i = 0; i < matched; ++i) { - EGLint gbm_format; - - if (platform == EGL_PLATFORM_WAYLAND_EXT) { - *out = configs[i]; - return true; - } - - if (!eglGetConfigAttrib(disp, - configs[i], - EGL_NATIVE_VISUAL_ID, - &gbm_format)) { + EGLint visual; + if (!eglGetConfigAttrib(disp, configs[i], + EGL_NATIVE_VISUAL_ID, &visual)) { continue; } - if (gbm_format == GBM_FORMAT_ARGB8888) { + if (visual == visual_id) { *out = configs[i]; return true; } @@ -110,7 +101,7 @@ static bool egl_get_config(EGLDisplay disp, EGLConfig *out, EGLenum platform) { return false; } -bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, +bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, EGLint visual_id, void *remote_display) { if (!egl_exts(egl)) { return false; @@ -133,7 +124,7 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, goto error; } - if (!egl_get_config(egl->display, &egl->config, platform)) { + if (!egl_get_config(egl->display, &egl->config, visual_id)) { wlr_log(L_ERROR, "Failed to get EGL config"); goto error; } -- cgit v1.2.3