switch-to-gtk3.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. From b2d08e79f8499723ae4dffe8068381dd108898cb Mon Sep 17 00:00:00 2001
  2. From: galtgendo <galtgendo>
  3. Date: Sat, 17 Aug 2013 20:55:04 +0200
  4. Subject: [PATCH] Switch to GTK+ 3
  5. ---
  6. configure.ac | 2 +-
  7. src/preview.c | 180 ++++++++++++++++++++++++++++++++++++----------------------
  8. 2 files changed, 112 insertions(+), 70 deletions(-)
  9. diff --git a/configure.ac b/configure.ac
  10. index b99620f..86df550 100644
  11. --- a/configure.ac
  12. +++ b/configure.ac
  13. @@ -27,7 +27,7 @@ PKG_CHECK_MODULES(LIBSTARTUPNOTIFICATION, [libstartup-notification-1.0])
  14. AC_SUBST(LIBSTARTUPNOTIFICATION_CFLAGS)
  15. AC_SUBST(LIBSTARTUPNOTIFICATION_LIBS)
  16. -PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.24.0])
  17. +PKG_CHECK_MODULES(GTK, [gtk+-3.0])
  18. AC_SUBST(GTK_CFLAGS)
  19. AC_SUBST(GTK_LIBS)
  20. diff --git a/src/preview.c b/src/preview.c
  21. index f52bb32..c00c3c0 100644
  22. --- a/src/preview.c
  23. +++ b/src/preview.c
  24. @@ -24,6 +24,8 @@
  25. #include <string.h>
  26. #include <obrender/theme.h>
  27. +#include <gdk/gdkx.h>
  28. +#include <cairo-xlib.h>
  29. #define PADDING 2 /* openbox does it :/ */
  30. @@ -53,7 +55,10 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  31. RrAppearance *selected;
  32. RrAppearance *bullet; /* for submenu */
  33. - GdkPixmap *pixmap;
  34. + cairo_surface_t *surface;
  35. + GdkScreen *screen;
  36. + Display *xdisplay;
  37. + Visual *xvisual;
  38. GdkPixbuf *pixbuf, *tmp_pixbuf;
  39. /* width and height of the whole menu */
  40. @@ -64,6 +69,10 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  41. gint bw, bh;
  42. gint unused;
  43. + screen = gdk_screen_get_default();
  44. + xdisplay = gdk_x11_get_default_xdisplay();
  45. + xvisual = gdk_x11_visual_get_xvisual(gdk_screen_get_system_visual(screen));
  46. +
  47. /* set up appearances */
  48. title = theme->a_menu_title;
  49. @@ -126,11 +135,13 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  50. theme_pixmap_paint(title_text, bw, title_h);
  51. - pixmap = gdk_pixmap_foreign_new(title_text->pixmap);
  52. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  53. - gdk_colormap_get_system(),
  54. - 0, 0, 0, 0,
  55. - bw, title_h);
  56. + surface = cairo_xlib_surface_create(xdisplay, title_text->pixmap,
  57. + xvisual,
  58. + bw, title_h);
  59. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  60. + 0, 0,
  61. + bw, title_h);
  62. + cairo_surface_destroy(surface);
  63. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, bw, title_h, pixbuf, x, y);
  64. y += title_h + theme->mbwidth;
  65. @@ -143,11 +154,13 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  66. /* draw background for normal entry */
  67. theme_pixmap_paint(background, bw, bh);
  68. - pixmap = gdk_pixmap_foreign_new(background->pixmap);
  69. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  70. - gdk_colormap_get_system(),
  71. - 0, 0, 0, 0,
  72. - bw, bh);
  73. + surface = cairo_xlib_surface_create(xdisplay, background->pixmap,
  74. + xvisual,
  75. + bw, bh);
  76. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  77. + 0, 0,
  78. + bw, bh);
  79. + cairo_surface_destroy(surface);
  80. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, bw, bh, pixbuf, x, y);
  81. /* draw normal entry */
  82. @@ -156,11 +169,13 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  83. normal->surface.parenty = PADDING;
  84. RrMinSize(normal, &tw, &th);
  85. theme_pixmap_paint(normal, tw, th);
  86. - pixmap = gdk_pixmap_foreign_new(normal->pixmap);
  87. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  88. - gdk_colormap_get_system(),
  89. - 0, 0, 0, 0,
  90. - tw, th);
  91. + surface = cairo_xlib_surface_create(xdisplay, normal->pixmap,
  92. + xvisual,
  93. + tw, th);
  94. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  95. + 0, 0,
  96. + tw, th);
  97. + cairo_surface_destroy(surface);
  98. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, tw, th, pixbuf,
  99. x + PADDING, y + PADDING);
  100. @@ -170,11 +185,13 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  101. bullet->surface.parentx = bw - th;
  102. bullet->surface.parenty = PADDING;
  103. theme_pixmap_paint(bullet, th, th);
  104. - pixmap = gdk_pixmap_foreign_new(bullet->pixmap);
  105. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  106. - gdk_colormap_get_system(),
  107. - 0, 0, 0, 0,
  108. - th, th);
  109. + surface = cairo_xlib_surface_create(xdisplay, bullet->pixmap,
  110. + xvisual,
  111. + th, th);
  112. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  113. + 0, 0,
  114. + th, th);
  115. + cairo_surface_destroy(surface);
  116. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, th, th, pixbuf,
  117. width - theme->mbwidth - th, y + PADDING);
  118. @@ -185,11 +202,13 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  119. background->surface.parentx = x - theme->mbwidth;
  120. background->surface.parenty = y - theme->mbwidth;
  121. theme_pixmap_paint(background, bw, bh);
  122. - pixmap = gdk_pixmap_foreign_new(background->pixmap);
  123. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  124. - gdk_colormap_get_system(),
  125. - 0, 0, 0, 0,
  126. - bw, bh);
  127. + surface = cairo_xlib_surface_create(xdisplay, background->pixmap,
  128. + xvisual,
  129. + bw, bh);
  130. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  131. + 0, 0,
  132. + bw, bh);
  133. + cairo_surface_destroy(surface);
  134. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, bw, bh, pixbuf, x, y);
  135. /* draw disabled entry */
  136. @@ -198,11 +217,13 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  137. disabled->surface.parentx = PADDING;
  138. disabled->surface.parenty = PADDING;
  139. theme_pixmap_paint(disabled, tw, th);
  140. - pixmap = gdk_pixmap_foreign_new(disabled->pixmap);
  141. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  142. - gdk_colormap_get_system(),
  143. - 0, 0, 0, 0,
  144. - tw, th);
  145. + surface = cairo_xlib_surface_create(xdisplay, disabled->pixmap,
  146. + xvisual,
  147. + tw, th);
  148. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  149. + 0, 0,
  150. + tw, th);
  151. + cairo_surface_destroy(surface);
  152. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, tw, th, pixbuf,
  153. x + PADDING, y + PADDING);
  154. @@ -215,11 +236,13 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  155. background->surface.parenty = y - theme->mbwidth;
  156. theme_pixmap_paint(background, bw, bh);
  157. - pixmap = gdk_pixmap_foreign_new(background->pixmap);
  158. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  159. - gdk_colormap_get_system(),
  160. - 0, 0, 0, 0,
  161. - bw, bh);
  162. + surface = cairo_xlib_surface_create(xdisplay, background->pixmap,
  163. + xvisual,
  164. + bw, bh);
  165. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  166. + 0, 0,
  167. + bw, bh);
  168. + cairo_surface_destroy(surface);
  169. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, bw, bh, pixbuf, x, y);
  170. /* draw selected entry */
  171. @@ -228,11 +251,13 @@ static GdkPixbuf* preview_menu(RrTheme *theme)
  172. selected->surface.parentx = PADDING;
  173. selected->surface.parenty = PADDING;
  174. theme_pixmap_paint(selected, tw, th);
  175. - pixmap = gdk_pixmap_foreign_new(selected->pixmap);
  176. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  177. - gdk_colormap_get_system(),
  178. - 0, 0, 0, 0,
  179. - tw, th);
  180. + surface = cairo_xlib_surface_create(xdisplay, selected->pixmap,
  181. + xvisual,
  182. + tw, th);
  183. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  184. + 0, 0,
  185. + tw, th);
  186. + cairo_surface_destroy(surface);
  187. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, tw, th, pixbuf,
  188. x + PADDING, y + PADDING);
  189. g_object_unref(tmp_pixbuf);
  190. @@ -247,7 +272,10 @@ static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
  191. RrAppearance *handle;
  192. RrAppearance *a;
  193. - GdkPixmap *pixmap;
  194. + cairo_surface_t *surface;
  195. + GdkScreen *screen;
  196. + Display *xdisplay;
  197. + Visual *xvisual;
  198. GdkPixbuf *pixbuf = NULL, *tmp_pixbuf = NULL;
  199. GdkPixbuf *scratch;
  200. @@ -255,6 +283,10 @@ static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
  201. const gchar *layout;
  202. + screen = gdk_screen_get_default();
  203. + xdisplay = gdk_x11_get_default_xdisplay();
  204. + xvisual = gdk_x11_visual_get_xvisual(gdk_screen_get_system_visual(screen));
  205. +
  206. title = focus ? theme->a_focused_title : theme->a_unfocused_title;
  207. /* set border */
  208. @@ -271,10 +303,12 @@ static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
  209. theme_pixmap_paint(title, w, h);
  210. x = y = theme->fbwidth;
  211. - pixmap = gdk_pixmap_foreign_new(title->pixmap);
  212. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  213. - gdk_colormap_get_system(),
  214. - 0, 0, 0, 0, w, h);
  215. + surface = cairo_xlib_surface_create(xdisplay, title->pixmap,
  216. + xvisual,
  217. + w, h);
  218. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  219. + 0, 0, w, h);
  220. + cairo_surface_destroy(surface);
  221. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);
  222. /* calculate label width */
  223. @@ -317,10 +351,12 @@ static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
  224. w = h = theme->button_size + 2;
  225. theme_pixmap_paint(a, w, h);
  226. - pixmap = gdk_pixmap_foreign_new(a->pixmap);
  227. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  228. - gdk_colormap_get_system(),
  229. - 0, 0, 0, 0, w, h);
  230. + surface = cairo_xlib_surface_create(xdisplay, a->pixmap,
  231. + xvisual,
  232. + w, h);
  233. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  234. + 0, 0, w, h);
  235. + cairo_surface_destroy(surface);
  236. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);
  237. x += theme->button_size + 2 + theme->paddingx + 1;
  238. @@ -335,10 +371,12 @@ static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
  239. h = theme->label_height;
  240. theme_pixmap_paint(a, w, h);
  241. - pixmap = gdk_pixmap_foreign_new(a->pixmap);
  242. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  243. - gdk_colormap_get_system(),
  244. - 0, 0, 0, 0, w, h);
  245. + surface = cairo_xlib_surface_create(xdisplay, a->pixmap,
  246. + xvisual,
  247. + w, h);
  248. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  249. + 0, 0, w, h);
  250. + cairo_surface_destroy(surface);
  251. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);
  252. x += w + theme->paddingx + 1;
  253. @@ -382,12 +420,14 @@ static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
  254. h = theme->button_size;
  255. theme_pixmap_paint(a, w, h);
  256. - pixmap = gdk_pixmap_foreign_new(a->pixmap);
  257. + surface = cairo_xlib_surface_create(xdisplay, a->pixmap,
  258. + xvisual,
  259. + w, h);
  260. /* use y + 1 because these buttons should be centered wrt the label
  261. */
  262. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  263. - gdk_colormap_get_system(),
  264. - 0, 0, 0, 0, w, h);
  265. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  266. + 0, 0, w, h);
  267. + cairo_surface_destroy(surface);
  268. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y + 1);
  269. x += theme->button_size + theme->paddingx + 1;
  270. @@ -403,10 +443,12 @@ static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
  271. h = theme->handle_height;
  272. theme_pixmap_paint(handle, w, h);
  273. - pixmap = gdk_pixmap_foreign_new(handle->pixmap);
  274. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  275. - gdk_colormap_get_system(),
  276. - 0, 0, 0, 0, w, h);
  277. + surface = cairo_xlib_surface_create(xdisplay, handle->pixmap,
  278. + xvisual,
  279. + w, h);
  280. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  281. + 0, 0, w, h);
  282. + cairo_surface_destroy(surface);
  283. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);
  284. /* openbox handles this drawing stuff differently (it fills the bottom
  285. @@ -425,17 +467,17 @@ static GdkPixbuf* preview_window(RrTheme *theme, const gchar *titlelayout,
  286. w = theme->grip_width;
  287. theme_pixmap_paint(a, w, h);
  288. - pixmap = gdk_pixmap_foreign_new(a->pixmap);
  289. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  290. - gdk_colormap_get_system(),
  291. - 0, 0, 0, 0, w, h);
  292. + surface = cairo_xlib_surface_create(xdisplay, a->pixmap,
  293. + xvisual, w, h);
  294. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  295. + 0, 0, w, h);
  296. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);
  297. /* right grip */
  298. x = width - theme->fbwidth - theme->grip_width;
  299. - tmp_pixbuf = gdk_pixbuf_get_from_drawable(tmp_pixbuf, pixmap,
  300. - gdk_colormap_get_system(),
  301. - 0, 0, 0, 0, w, h);
  302. + tmp_pixbuf = gdk_pixbuf_get_from_surface(surface,
  303. + 0, 0, w, h);
  304. + cairo_surface_destroy(surface);
  305. gdk_pixbuf_copy_area(tmp_pixbuf, 0, 0, w, h, pixbuf, x, y);
  306. }
  307. --
  308. 1.9.1