Ejemplo n.º 1
0
static void
pointer_handle_enter(void *data, struct wl_pointer *pointer,
		     uint32_t serial, struct wl_surface *surface,
		     wl_fixed_t sx, wl_fixed_t sy)
{
	struct display *display = data;
	struct wl_buffer *buffer;
	struct wl_cursor *cursor = display->default_cursor;
	struct wl_cursor_image *image;

	if (display->window->fullscreen)
		wl_pointer_set_cursor(pointer, serial, NULL, 0, 0);
	else if (cursor) {
		image = display->default_cursor->images[0];
		buffer = wl_cursor_image_get_buffer(image);
		wl_pointer_set_cursor(pointer, serial,
				      display->cursor_surface,
				      image->hotspot_x,
				      image->hotspot_y);
		wl_surface_attach(display->cursor_surface, buffer, 0, 0);
		wl_surface_damage(display->cursor_surface, 0, 0,
				  image->width, image->height);
		wl_surface_commit(display->cursor_surface);
	}
}
Ejemplo n.º 2
0
struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface) {
	struct window *window = malloc(sizeof(struct window));
	memset(window, 0, sizeof(struct window));
	window->width = width;
	window->height = height;
	window->registry = registry;

	window->surface = wl_compositor_create_surface(registry->compositor);
	if (shell_surface) {
		window->shell_surface = wl_shell_get_shell_surface(registry->shell, window->surface);
		wl_shell_surface_add_listener(window->shell_surface, &surface_listener, window);
		wl_shell_surface_set_toplevel(window->shell_surface);
	}
	if (registry->pointer) {
		wl_pointer_add_listener(registry->pointer, &pointer_listener, window);
	}

	window->cursor.cursor_theme = wl_cursor_theme_load("default", 32, registry->shm); // TODO: let you customize this
	window->cursor.cursor = wl_cursor_theme_get_cursor(window->cursor.cursor_theme, "left_ptr");
	window->cursor.surface = wl_compositor_create_surface(registry->compositor);

	struct wl_cursor_image *image = window->cursor.cursor->images[0];
	struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
	wl_surface_attach(window->cursor.surface, cursor_buf, 0, 0);
	wl_surface_damage(window->cursor.surface, 0, 0, image->width, image->height);
	wl_surface_commit(window->cursor.surface);

	return window;
}
Ejemplo n.º 3
0
static void
clutter_backend_wayland_load_cursor (ClutterBackendWayland *backend_wayland)
{
  struct wl_cursor *cursor;

  backend_wayland->cursor_theme =
    wl_cursor_theme_load (NULL, /* default */
                          32,
                          backend_wayland->wayland_shm);

  cursor = wl_cursor_theme_get_cursor (backend_wayland->cursor_theme,
                                       "left_ptr");

  backend_wayland->cursor_buffer =
    wl_cursor_image_get_buffer (cursor->images[0]);

  if (backend_wayland->cursor_buffer)
    {
      backend_wayland->cursor_x = cursor->images[0]->hotspot_x;
      backend_wayland->cursor_y = cursor->images[0]->hotspot_y;
    }

  backend_wayland->cursor_surface =
    wl_compositor_create_surface (backend_wayland->wayland_compositor);
}
Ejemplo n.º 4
0
static void setCursor(const char* name)
{
    struct wl_buffer* buffer;
    struct wl_cursor* cursor;
    struct wl_cursor_image* image;
    struct wl_surface* surface = _glfw.wl.cursorSurface;

    cursor = wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme,
                                        name);
    if (!cursor)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Standard cursor not found");
        return;
    }
    image = cursor->images[0];

    if (!image)
        return;

    buffer = wl_cursor_image_get_buffer(image);
    if (!buffer)
        return;
    wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.pointerSerial,
                          surface,
                          image->hotspot_x,
                          image->hotspot_y);
    wl_surface_attach(surface, buffer, 0, 0);
    wl_surface_damage(surface, 0, 0,
                      image->width, image->height);
    wl_surface_commit(surface);
}
Ejemplo n.º 5
0
struct wl_buffer *
_gdk_wayland_cursor_get_buffer (GdkCursor *cursor,
                                guint      image_index,
                                int       *hotspot_x,
                                int       *hotspot_y,
                                int       *w,
                                int       *h,
				int       *scale)
{
  GdkWaylandCursor *wayland_cursor = GDK_WAYLAND_CURSOR (cursor);

  if (wayland_cursor->wl_cursor)
    {
      struct wl_cursor_image *image;

      if (image_index >= wayland_cursor->wl_cursor->image_count)
        {
          g_warning (G_STRLOC " out of bounds cursor image [%d / %d]",
                     image_index,
                     wayland_cursor->wl_cursor->image_count - 1);
          image_index = 0;
        }

      image = wayland_cursor->wl_cursor->images[image_index];

      *hotspot_x = image->hotspot_x / wayland_cursor->scale;
      *hotspot_y = image->hotspot_y / wayland_cursor->scale;

      *w = image->width / wayland_cursor->scale;
      *h = image->height / wayland_cursor->scale;
      *scale = wayland_cursor->scale;

      return wl_cursor_image_get_buffer (image);
    }
  else if (wayland_cursor->name == NULL) /* From surface */
    {
      *hotspot_x =
        wayland_cursor->surface.hotspot_x / wayland_cursor->surface.scale;
      *hotspot_y =
        wayland_cursor->surface.hotspot_y / wayland_cursor->surface.scale;

      *w = wayland_cursor->surface.width / wayland_cursor->surface.scale;
      *h = wayland_cursor->surface.height / wayland_cursor->surface.scale;
      *scale = wayland_cursor->surface.scale;

      cairo_surface_reference (wayland_cursor->surface.cairo_surface);

      if (wayland_cursor->surface.cairo_surface)
        return _gdk_wayland_shm_surface_get_wl_buffer (wayland_cursor->surface.cairo_surface);
    }

  return NULL;
}
Ejemplo n.º 6
0
static void
_eventd_nd_cursor_set_image(EventdNdBackendContext *self, int i)
{
    struct wl_buffer *buffer;
    struct wl_cursor_image *image;
    image = self->cursor.cursor->images[i];

    self->cursor.image = image;
    buffer = wl_cursor_image_get_buffer(self->cursor.image);
    wl_surface_attach(self->cursor.surface, buffer, 0, 0);
    wl_surface_damage(self->cursor.surface, 0, 0, self->cursor.image->width, self->cursor.image->height);
    wl_surface_commit(self->cursor.surface);
}
Ejemplo n.º 7
0
struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height,
		int32_t scale, bool shell_surface) {
	struct window *window = malloc(sizeof(struct window));
	memset(window, 0, sizeof(struct window));
	window->width = width;
	window->height = height;
	window->scale = scale;
	window->registry = registry;
	window->font = "monospace 10";

	window->surface = wl_compositor_create_surface(registry->compositor);
	if (shell_surface) {
		window_make_shell(window);
	}
	if (registry->pointer) {
		wl_pointer_add_listener(registry->pointer, &pointer_listener, window);
	}

	get_next_buffer(window);

	if (registry->pointer) {
		char *cursor_theme = getenv("SWAY_CURSOR_THEME");
		if (!cursor_theme) {
			cursor_theme = "default";
		}
		char *cursor_size = getenv("SWAY_CURSOR_SIZE");
		if (!cursor_size) {
			cursor_size = "16";
		}

		sway_log(L_DEBUG, "Cursor scale: %d", scale);
		window->cursor.cursor_theme = wl_cursor_theme_load(cursor_theme,
				atoi(cursor_size) * scale, registry->shm);
		window->cursor.cursor = wl_cursor_theme_get_cursor(window->cursor.cursor_theme, "left_ptr");
		window->cursor.surface = wl_compositor_create_surface(registry->compositor);

		struct wl_cursor_image *image = window->cursor.cursor->images[0];
		struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
		wl_surface_attach(window->cursor.surface, cursor_buf, 0, 0);
		wl_surface_set_buffer_scale(window->cursor.surface, scale);
		wl_surface_damage(window->cursor.surface, 0, 0,
				image->width, image->height);
		wl_surface_commit(window->cursor.surface);
	}

	return window;
}
Ejemplo n.º 8
0
static struct cursor_surface *
cursor_viewer_show_cursor(struct cursor_viewer *viewer, const char *name)
{
    struct wl_cursor_image *cursor_image;
    struct wl_buffer *cursor_buffer = NULL;

    struct cursor_surface *cursor = calloc(1, sizeof (struct cursor_surface));
    if (!cursor)
        die("Cannot allocate memory for cursor_surface\n");

    cursor->name = name;
    cursor->surface = wl_compositor_create_surface(viewer->compositor);
    cursor->shsurf = wl_shell_get_shell_surface(viewer->shell, cursor->surface);

    wl_shell_surface_add_listener(cursor->shsurf, &shsurf_listener, viewer);
    wl_shell_surface_set_toplevel(cursor->shsurf);
    wl_shell_surface_set_title(cursor->shsurf, name);
    wl_surface_set_user_data(cursor->surface, viewer);

    cursor->cursor = wl_cursor_theme_get_cursor(viewer->cursor_theme, name);
    if (!cursor->cursor || cursor->cursor->image_count < 1) {
        printf("No such cursor: %s\n", name);
        cursor_surface_destroy(cursor);
        return NULL;
    }

    cursor_image = cursor->cursor->images[0];
    cursor_buffer = wl_cursor_image_get_buffer(cursor_image);

    printf("%s: %s: size=%dx%d image_count=%u\n",
        __func__, cursor->name,
        cursor_image->width, cursor_image->height,
        cursor->cursor->image_count);

    if (cursor->cursor->image_count > 1) {
        cursor->frame = wl_surface_frame(cursor->surface);
        wl_callback_add_listener(cursor->frame, &frame_listener, cursor);
    }

    wl_surface_attach(cursor->surface, cursor_buffer, 0, 0);
    wl_surface_damage(cursor->surface, 0, 0, cursor_image->width, cursor_image->height);
    wl_surface_commit(cursor->surface);

    return cursor;
}
Ejemplo n.º 9
0
static void gfx_ctx_wl_show_mouse(void *data, bool state)
{
   gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
   if (!wl->wl_pointer)
      return;

   if (state)
   {
      struct wl_cursor_image *image = wl->cursor.default_cursor->images[0];
      wl_pointer_set_cursor(wl->wl_pointer, wl->cursor.serial, wl->cursor.surface, image->hotspot_x, image->hotspot_y);
      wl_surface_attach(wl->cursor.surface, wl_cursor_image_get_buffer(image), 0, 0);
      wl_surface_damage(wl->cursor.surface, 0, 0, image->width, image->height);
      wl_surface_commit(wl->cursor.surface);
   }
   else
      wl_pointer_set_cursor(wl->wl_pointer, wl->cursor.serial, NULL, 0, 0);

   wl->cursor.visible = state;
}
Ejemplo n.º 10
0
static Eina_Bool
_ecore_wl_input_cursor_update(void *data)
{
   struct wl_cursor_image *cursor_image;
   struct wl_buffer *buffer;
   Ecore_Wl_Input *input = data;
   unsigned int delay;

   if ((!input) || (!input->cursor)) return EINA_FALSE;

   cursor_image = input->cursor->images[input->cursor_current_index];
   if (!cursor_image) return ECORE_CALLBACK_RENEW;

   if ((buffer = wl_cursor_image_get_buffer(cursor_image)))
     {
        ecore_wl_input_pointer_set(input, input->cursor_surface,
                                   cursor_image->hotspot_x,
                                   cursor_image->hotspot_y);
        wl_surface_attach(input->cursor_surface, buffer, 0, 0);
        wl_surface_damage(input->cursor_surface, 0, 0,
                          cursor_image->width, cursor_image->height);
        wl_surface_commit(input->cursor_surface);

        if ((input->cursor->image_count > 1) && (!input->cursor_frame_cb))
          _ecore_wl_input_cb_pointer_frame(input, NULL, 0);
     }

   if (input->cursor->image_count <= 1)
     return ECORE_CALLBACK_CANCEL;

   delay = cursor_image->delay;
   input->cursor_current_index =
      (input->cursor_current_index + 1) % input->cursor->image_count;

   if (!input->cursor_timer)
     input->cursor_timer =
        ecore_timer_loop_add(delay / 1000.0,
                             _ecore_wl_input_cursor_update, input);
   else
     ecore_timer_interval_set(input->cursor_timer, delay / 1000.0);

   return ECORE_CALLBACK_RENEW;
}
Ejemplo n.º 11
0
static void
surface_frame_done(void *data, struct wl_callback *wl_callback, uint32_t time)
{
    struct wl_cursor_image *cursor_image;
    struct wl_buffer *cursor_buffer = NULL;
    struct cursor_surface *cursor = (struct cursor_surface *)data;
    int image_index = wl_cursor_frame(cursor->cursor, time);

    cursor_image = cursor->cursor->images[image_index];
    cursor_buffer = wl_cursor_image_get_buffer(cursor_image);

    if (cursor->frame)
        wl_callback_destroy(cursor->frame);
    cursor->frame = wl_surface_frame(cursor->surface);
    wl_callback_add_listener(cursor->frame, &frame_listener, cursor);
    wl_surface_attach(cursor->surface, cursor_buffer, 0, 0);
    wl_surface_damage(cursor->surface, 0, 0, cursor_image->width, cursor_image->height);
    wl_surface_commit(cursor->surface);
}
Ejemplo n.º 12
0
static void setCursor(_GLFWwindow* window, const char* name)
{
    struct wl_buffer* buffer;
    struct wl_cursor* cursor;
    struct wl_cursor_image* image;
    struct wl_surface* surface = _glfw.wl.cursorSurface;
    struct wl_cursor_theme* theme = _glfw.wl.cursorTheme;
    int scale = 1;

    if (window->wl.scale > 1 && _glfw.wl.cursorThemeHiDPI)
    {
        // We only support up to scale=2 for now, since libwayland-cursor
        // requires us to load a different theme for each size.
        scale = 2;
        theme = _glfw.wl.cursorThemeHiDPI;
    }

    cursor = wl_cursor_theme_get_cursor(theme, name);
    if (!cursor)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Standard cursor not found");
        return;
    }
    // TODO: handle animated cursors too.
    image = cursor->images[0];

    if (!image)
        return;

    buffer = wl_cursor_image_get_buffer(image);
    if (!buffer)
        return;
    wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.serial,
                          surface,
                          image->hotspot_x / scale,
                          image->hotspot_y / scale);
    wl_surface_set_buffer_scale(surface, scale);
    wl_surface_attach(surface, buffer, 0, 0);
    wl_surface_damage(surface, 0, 0,
                      image->width, image->height);
    wl_surface_commit(surface);
}
Ejemplo n.º 13
0
/*
 * This function will effectively set the pointer (mouse) cursor
 * depending on the GLUT_CURSOR_* choice.
 */
void fghPointerSetCursor( SFG_Window* window,
                          struct wl_pointer* pointer,
                          uint32_t serial )
{
    struct wl_cursor_image* image;
    struct wl_buffer* buffer;

    image = window->Window.pContext.cursor->images[0];
    buffer = wl_cursor_image_get_buffer( image );

    wl_surface_attach( window->Window.pContext.cursor_surface, buffer,
                       0, 0 );
    wl_surface_damage( window->Window.pContext.cursor_surface, 0, 0,
                       image->width, image->height );
    wl_surface_commit( window->Window.pContext.cursor_surface );

    wl_pointer_set_cursor( pointer, serial,
                           window->Window.pContext.cursor_surface,
                           image->hotspot_x, image->hotspot_y );
}
static void
pointer_handle_enter (void *data, struct wl_pointer *pointer, uint32_t serial,
    struct wl_surface *surface, wl_fixed_t sx_w, wl_fixed_t sy_w)
{
  GstGLWindowWaylandEGL *window_egl = data;
  struct wl_buffer *buffer;
  struct wl_cursor_image *image = NULL;

  window_egl->display.serial = serial;

  if (window_egl->display.default_cursor) {
    image = window_egl->display.default_cursor->images[0];
    buffer = wl_cursor_image_get_buffer (image);
    wl_pointer_set_cursor (pointer, serial,
        window_egl->display.cursor_surface, image->hotspot_x, image->hotspot_y);
    wl_surface_attach (window_egl->display.cursor_surface, buffer, 0, 0);
    wl_surface_damage (window_egl->display.cursor_surface, 0, 0,
        image->width, image->height);
    wl_surface_commit (window_egl->display.cursor_surface);
  }
}