cursor-renderer: Move x11 specific bits to CursorRendererX11

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3599>
This commit is contained in:
Bilal Elmoussaoui 2024-02-20 13:02:54 +01:00 committed by Marge Bot
parent 899b4aad37
commit c72e129eb2
3 changed files with 39 additions and 41 deletions

View File

@ -95,33 +95,6 @@ meta_cursor_get_name (MetaCursor cursor)
return NULL; return NULL;
} }
static Cursor
create_blank_cursor (Display *xdisplay)
{
Pixmap pixmap;
XColor color;
Cursor cursor;
XGCValues gc_values;
GC gc;
pixmap = XCreatePixmap (xdisplay, DefaultRootWindow (xdisplay), 1, 1, 1);
gc_values.foreground = BlackPixel (xdisplay, DefaultScreen (xdisplay));
gc = XCreateGC (xdisplay, pixmap, GCForeground, &gc_values);
XFillRectangle (xdisplay, pixmap, gc, 0, 0, 1, 1);
color.pixel = 0;
color.red = color.blue = color.green = 0;
cursor = XCreatePixmapCursor (xdisplay, pixmap, pixmap, &color, &color, 1, 1);
XFreeGC (xdisplay, gc);
XFreePixmap (xdisplay, pixmap);
return cursor;
}
static XcursorImages * static XcursorImages *
create_blank_cursor_images (void) create_blank_cursor_images (void)
{ {
@ -143,16 +116,6 @@ meta_cursor_sprite_xcursor_get_cursor (MetaCursorSpriteXcursor *sprite_xcursor)
return sprite_xcursor->cursor; return sprite_xcursor->cursor;
} }
Cursor
meta_create_x_cursor (Display *xdisplay,
MetaCursor cursor)
{
if (cursor == META_CURSOR_BLANK)
return create_blank_cursor (xdisplay);
return XcursorLibraryLoadCursor (xdisplay, meta_cursor_get_name (cursor));
}
static XcursorImages * static XcursorImages *
load_cursor_on_client (MetaCursor cursor, int scale) load_cursor_on_client (MetaCursor cursor, int scale)
{ {

View File

@ -38,7 +38,4 @@ MetaCursor meta_cursor_sprite_xcursor_get_cursor (MetaCursorSpriteXcursor *sprit
XcursorImage * meta_cursor_sprite_xcursor_get_current_image (MetaCursorSpriteXcursor *sprite_xcursor); XcursorImage * meta_cursor_sprite_xcursor_get_current_image (MetaCursorSpriteXcursor *sprite_xcursor);
Cursor meta_create_x_cursor (Display *xdisplay,
MetaCursor cursor);
const char * meta_cursor_get_name (MetaCursor cursor); const char * meta_cursor_get_name (MetaCursor cursor);

View File

@ -39,6 +39,44 @@ struct _MetaCursorRendererX11
G_DEFINE_FINAL_TYPE (MetaCursorRendererX11, meta_cursor_renderer_x11, META_TYPE_CURSOR_RENDERER); G_DEFINE_FINAL_TYPE (MetaCursorRendererX11, meta_cursor_renderer_x11, META_TYPE_CURSOR_RENDERER);
static Cursor
create_blank_cursor (Display *xdisplay)
{
Pixmap pixmap;
XColor color;
Cursor cursor;
XGCValues gc_values;
GC gc;
pixmap = XCreatePixmap (xdisplay, DefaultRootWindow (xdisplay), 1, 1, 1);
gc_values.foreground = BlackPixel (xdisplay, DefaultScreen (xdisplay));
gc = XCreateGC (xdisplay, pixmap, GCForeground, &gc_values);
XFillRectangle (xdisplay, pixmap, gc, 0, 0, 1, 1);
color.pixel = 0;
color.red = color.blue = color.green = 0;
cursor = XCreatePixmapCursor (xdisplay, pixmap, pixmap, &color, &color, 1, 1);
XFreeGC (xdisplay, gc);
XFreePixmap (xdisplay, pixmap);
return cursor;
}
static Cursor
create_x_cursor (Display *xdisplay,
MetaCursor cursor)
{
if (cursor == META_CURSOR_BLANK)
return create_blank_cursor (xdisplay);
return XcursorLibraryLoadCursor (xdisplay, meta_cursor_get_name (cursor));
}
static gboolean static gboolean
meta_cursor_renderer_x11_update_cursor (MetaCursorRenderer *renderer, meta_cursor_renderer_x11_update_cursor (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite) MetaCursorSprite *cursor_sprite)
@ -69,7 +107,7 @@ meta_cursor_renderer_x11_update_cursor (MetaCursorRenderer *renderer,
{ {
Cursor xcursor; Cursor xcursor;
xcursor = meta_create_x_cursor (xdisplay, cursor); xcursor = create_x_cursor (xdisplay, cursor);
XDefineCursor (xdisplay, xwindow, xcursor); XDefineCursor (xdisplay, xwindow, xcursor);
XFlush (xdisplay); XFlush (xdisplay);
XFreeCursor (xdisplay, xcursor); XFreeCursor (xdisplay, xcursor);