wayland: Load cursors from wayland directory under XDG_DATA_DIRS
This means we don't have to have hardcoded "/usr/share/wayland" to find the cursors. This change also fixes up the warning messages for when loading fails.
This commit is contained in:
		| @ -234,21 +234,19 @@ create_cursor(GdkDisplayWayland *display, GdkPixbuf *pixbuf, int x, int y) | ||||
|   return GDK_CURSOR (cursor); | ||||
| } | ||||
|  | ||||
| #define DATADIR "/usr/share/wayland" | ||||
|  | ||||
| static const struct { | ||||
|   GdkCursorType type; | ||||
|   const char *filename; | ||||
|   int hotspot_x, hotspot_y; | ||||
| } cursor_definitions[] = { | ||||
|   { GDK_BLANK_CURSOR, NULL, 0, 0 }, | ||||
|   { GDK_HAND1, DATADIR "/hand1.png", 18, 11 }, | ||||
|   { GDK_HAND2, DATADIR "/hand2.png", 14,  8 }, | ||||
|   { GDK_LEFT_PTR, DATADIR "/left_ptr.png", 10, 5 }, | ||||
|   { GDK_SB_H_DOUBLE_ARROW, DATADIR "/sb_h_double_arrow.png", 15, 15 }, | ||||
|   { GDK_SB_V_DOUBLE_ARROW, DATADIR "/sb_v_double_arrow.png", 15, 15 }, | ||||
|   { GDK_XTERM, DATADIR "/xterm.png", 15, 15 }, | ||||
|   { GDK_BOTTOM_RIGHT_CORNER, DATADIR "/bottom_right_corner.png", 28, 28 } | ||||
|   { GDK_HAND1, "hand1.png", 18, 11 }, | ||||
|   { GDK_HAND2, "hand2.png", 14,  8 }, | ||||
|   { GDK_LEFT_PTR, "left_ptr.png", 10, 5 }, | ||||
|   { GDK_SB_H_DOUBLE_ARROW, "sb_h_double_arrow.png", 15, 15 }, | ||||
|   { GDK_SB_V_DOUBLE_ARROW, "sb_v_double_arrow.png", 15, 15 }, | ||||
|   { GDK_XTERM, "xterm.png", 15, 15 }, | ||||
|   { GDK_BOTTOM_RIGHT_CORNER, "bottom_right_corner.png", 28, 28 } | ||||
| }; | ||||
|  | ||||
| GdkCursor * | ||||
| @ -256,7 +254,7 @@ _gdk_wayland_display_get_cursor_for_type (GdkDisplay    *display, | ||||
| 					  GdkCursorType  cursor_type) | ||||
| { | ||||
|   GdkDisplayWayland *wayland_display; | ||||
|   GdkPixbuf *pixbuf; | ||||
|   GdkPixbuf *pixbuf = NULL; | ||||
|   GError *error = NULL; | ||||
|   int i; | ||||
|  | ||||
| @ -268,8 +266,8 @@ _gdk_wayland_display_get_cursor_for_type (GdkDisplay    *display, | ||||
|  | ||||
|   if (i == G_N_ELEMENTS (cursor_definitions)) | ||||
|     { | ||||
|       g_warning("unhandled cursor type %d, falling back to blank\n", | ||||
| 		cursor_type); | ||||
|       g_warning ("Unhandled cursor type %d, falling back to blank\n", | ||||
|                  cursor_type); | ||||
|       i = 0; | ||||
|     } | ||||
|  | ||||
| @ -281,20 +279,44 @@ _gdk_wayland_display_get_cursor_for_type (GdkDisplay    *display, | ||||
|     return g_object_ref (wayland_display->cursors[i]); | ||||
|  | ||||
|   GDK_NOTE (CURSOR, | ||||
| 	    g_message ("creating new cursor for type %d, filename %s", | ||||
| 	    g_message ("Creating new cursor for type %d, filename %s", | ||||
| 		       cursor_type, cursor_definitions[i].filename)); | ||||
|  | ||||
|   if (cursor_type != GDK_BLANK_CURSOR) | ||||
|     pixbuf = gdk_pixbuf_new_from_file(cursor_definitions[i].filename, &error); | ||||
|   else | ||||
|     pixbuf = NULL; | ||||
|   if (error != NULL) | ||||
|     { | ||||
|       GDK_NOTE (CURSOR, | ||||
| 		g_message ("failed to load %s: %s", | ||||
| 			   cursor_definitions[i].filename, error->message)); | ||||
|       g_error_free(error); | ||||
|       return NULL; | ||||
|       const gchar * const *directories; | ||||
|       gint j; | ||||
|  | ||||
|       directories = g_get_system_data_dirs(); | ||||
|  | ||||
|       for (j = 0; directories[j] != NULL; j++) | ||||
|         { | ||||
|           gchar *filename; | ||||
|           filename = g_build_filename (directories[j], | ||||
|                                        "wayland", | ||||
|                                        cursor_definitions[i].filename, | ||||
|                                        NULL); | ||||
|           if (g_file_test (filename, G_FILE_TEST_EXISTS)) | ||||
|             { | ||||
|               pixbuf = gdk_pixbuf_new_from_file (filename, &error); | ||||
|  | ||||
|               if (error != NULL) | ||||
|                 { | ||||
|                   g_warning ("Failed to load cursor: %s: %s", | ||||
|                              filename, error->message); | ||||
|                   g_error_free(error); | ||||
|                   return NULL; | ||||
|                 } | ||||
|               break; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|       if (!pixbuf) | ||||
|         { | ||||
|           g_warning ("Unable to find cursor for: %s", | ||||
|                      cursor_definitions[i].filename); | ||||
|           return NULL; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   wayland_display->cursors[i] = | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Rob Bradford
					Rob Bradford