From a916f2cd5523dd0cccbcc87dcc22671a5a6df15b Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 17 Aug 2009 16:38:56 +0200 Subject: [PATCH] image: port to new class system Signed-off-by: Julien Danjou --- awesome.c | 3 +- button.c | 1 + client.c | 1 + client.h | 2 +- ewmh.c | 1 + hooks.c | 1 + image.c | 140 ++++++++++++++++++++++++------------------ image.h | 25 ++------ key.c | 3 +- key.h | 2 +- keygrabber.c | 1 + luaa.c | 5 +- luaa.h | 1 + mouse.c | 1 + mousegrabber.c | 3 +- property.c | 3 +- root.c | 1 + screen.c | 1 + structs.h | 3 + tag.c | 1 + timer.c | 1 + titlebar.c | 3 +- wibox.c | 1 + wibox.h | 1 + widget.c | 1 + widgets/graph.c | 1 + widgets/imagebox.c | 3 +- widgets/progressbar.c | 3 +- widgets/textbox.c | 1 + 29 files changed, 122 insertions(+), 92 deletions(-) diff --git a/awesome.c b/awesome.c index 2ce1bb51..295825ae 100644 --- a/awesome.c +++ b/awesome.c @@ -26,8 +26,6 @@ #include #include -#include - #include #include @@ -42,6 +40,7 @@ #include "property.h" #include "screen.h" #include "titlebar.h" +#include "luaa.h" #include "common/version.h" #include "common/atoms.h" #include "common/xcursor.h" diff --git a/button.c b/button.c index 54e7d0da..5d9c78cb 100644 --- a/button.c +++ b/button.c @@ -22,6 +22,7 @@ #include "button.h" #include "luaa.h" #include "key.h" +#include "common/luaobject.h" /** Create a new mouse button bindings. * \param L The Lua VM state. diff --git a/client.c b/client.c index 9335e952..1370f227 100644 --- a/client.c +++ b/client.c @@ -29,6 +29,7 @@ #include "systray.h" #include "property.h" #include "spawn.h" +#include "luaa.h" #include "common/atoms.h" #include "common/xutil.h" diff --git a/client.h b/client.h index cfa8d134..3acd0b07 100644 --- a/client.h +++ b/client.h @@ -24,7 +24,7 @@ #include "mouse.h" #include "stack.h" -#include "common/luaclass.h" +#include "common/luaobject.h" #define CLIENT_SELECT_INPUT_EVENT_MASK (XCB_EVENT_MASK_STRUCTURE_NOTIFY \ | XCB_EVENT_MASK_PROPERTY_CHANGE \ diff --git a/ewmh.c b/ewmh.c index 23c5e016..e208f371 100644 --- a/ewmh.c +++ b/ewmh.c @@ -31,6 +31,7 @@ #include "client.h" #include "widget.h" #include "wibox.h" +#include "luaa.h" #include "common/atoms.h" #include "common/buffer.h" #include "common/xutil.h" diff --git a/hooks.c b/hooks.c index 54055c6d..03f64b3f 100644 --- a/hooks.c +++ b/hooks.c @@ -20,6 +20,7 @@ */ #include "structs.h" +#include "luaa.h" #define HANDLE_HOOK(L, h) \ do { \ diff --git a/image.c b/image.c index 3da494a8..3b0edf5d 100644 --- a/image.c +++ b/image.c @@ -19,11 +19,28 @@ * */ -#include "structs.h" -#include "common/tokenize.h" -#include "common/xutil.h" #include +#include + +#include "structs.h" +#include "luaa.h" +#include "common/luaobject.h" + +struct image +{ + LUA_OBJECT_HEADER + /** Imlib2 image */ + Imlib_Image image; + /** Image data */ + uint8_t *data; + /** Flag telling if the image is up to date or needs computing before + * drawing */ + bool isupdated; +}; + +LUA_OBJECT_FUNCS(image_class, image_t, image) + static int luaA_image_gc(lua_State *L) { @@ -729,68 +746,73 @@ luaA_image_insert(lua_State *L) return 0; } -/** Image object. - * \param L The Lua VM state. - * \return The number of elements pushed on stack. - * \luastack - * \lvalue An image - * \lfield width The image width. - * \lfield height The image height. - */ static int -luaA_image_index(lua_State *L) +luaA_image_get_width(lua_State *L, image_t *image) { - if(luaA_usemetatable(L, 1, 2)) - return 1; - - image_t *image = luaA_checkudata(L, 1, &image_class); - size_t len; - const char *attr = luaL_checklstring(L, 2, &len); - - switch(a_tokenize(attr, len)) - { - case A_TK_WIDTH: - lua_pushnumber(L, image_getwidth(image)); - break; - case A_TK_HEIGHT: - lua_pushnumber(L, image_getheight(image)); - break; - case A_TK_ALPHA: - imlib_context_set_image(image->image); - lua_pushboolean(L, imlib_image_has_alpha()); - break; - default: - return 0; - } - + lua_pushnumber(L, image_getwidth(image)); return 1; } -const struct luaL_reg awesome_image_methods[] = +static int +luaA_image_get_height(lua_State *L, image_t *image) { - LUA_CLASS_METHODS(image) - { "__call", luaA_image_new }, - { "argb32", luaA_image_argb32_new }, - { NULL, NULL } -}; -const struct luaL_reg awesome_image_meta[] = + lua_pushnumber(L, image_getheight(image)); + return 1; +} + +static int +luaA_image_get_alpha(lua_State *L, image_t *image) { - LUA_OBJECT_META(image) - { "__index", luaA_image_index }, - { "rotate", luaA_image_rotate }, - { "orientate", luaA_image_orientate }, - { "crop", luaA_image_crop }, - { "crop_and_scale", luaA_image_crop_and_scale }, - { "save", luaA_image_save }, - { "insert", luaA_image_insert }, - /* draw on images, whee! */ - { "draw_pixel", luaA_image_draw_pixel }, - { "draw_line", luaA_image_draw_line }, - { "draw_rectangle", luaA_image_draw_rectangle }, - { "draw_rectangle_gradient", luaA_image_draw_rectangle_gradient }, - { "draw_circle", luaA_image_draw_circle }, - { "__gc", luaA_image_gc }, - { NULL, NULL } -}; + imlib_context_set_image(image->image); + lua_pushboolean(L, imlib_image_has_alpha()); + return 1; +} + +void +image_class_setup(lua_State *L) +{ + static const struct luaL_reg image_methods[] = + { + LUA_CLASS_METHODS(image) + { "__call", luaA_image_new }, + { "argb32", luaA_image_argb32_new }, + { NULL, NULL } + }; + + static const struct luaL_reg image_meta[] = + { + LUA_OBJECT_META(image) + LUA_CLASS_META + { "rotate", luaA_image_rotate }, + { "orientate", luaA_image_orientate }, + { "crop", luaA_image_crop }, + { "crop_and_scale", luaA_image_crop_and_scale }, + { "save", luaA_image_save }, + { "insert", luaA_image_insert }, + /* draw on images, whee! */ + { "draw_pixel", luaA_image_draw_pixel }, + { "draw_line", luaA_image_draw_line }, + { "draw_rectangle", luaA_image_draw_rectangle }, + { "draw_rectangle_gradient", luaA_image_draw_rectangle_gradient }, + { "draw_circle", luaA_image_draw_circle }, + { "__gc", luaA_image_gc }, + { NULL, NULL } + }; + + luaA_class_setup(L, &image_class, "image", (lua_class_allocator_t) image_new, + image_methods, image_meta); + luaA_class_add_property(&image_class, A_TK_WIDTH, + NULL, + (lua_class_propfunc_t) luaA_image_get_width, + NULL); + luaA_class_add_property(&image_class, A_TK_HEIGHT, + NULL, + (lua_class_propfunc_t) luaA_image_get_height, + NULL); + luaA_class_add_property(&image_class, A_TK_ALPHA, + NULL, + (lua_class_propfunc_t) luaA_image_get_alpha, + NULL); +} // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/image.h b/image.h index 08c0164c..ed1e71aa 100644 --- a/image.h +++ b/image.h @@ -1,7 +1,7 @@ /* * image.h - image object header * - * Copyright © 2008 Julien Danjou + * Copyright © 2008-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,27 +22,12 @@ #ifndef AWESOME_IMAGE_H #define AWESOME_IMAGE_H -#include - -#include "common/util.h" -#include "common/luaobject.h" +#include #include "common/luaclass.h" -typedef struct -{ - LUA_OBJECT_HEADER - /** Imlib2 image */ - Imlib_Image image; - /** Image data */ - uint8_t *data; - /** Flag telling if the image is up to date or needs computing before - * drawing */ - bool isupdated; -} image_t; - -lua_class_t image_class; -LUA_OBJECT_FUNCS(image_class, image_t, image) +typedef struct image image_t; +void image_class_setup(lua_State *); int image_new_from_argb32(int, int, uint32_t *); uint8_t * image_getdata(image_t *); int image_getwidth(image_t *); @@ -50,5 +35,7 @@ int image_getheight(image_t *); xcb_pixmap_t image_to_1bit_pixmap(image_t *, xcb_drawable_t); +lua_class_t image_class; + #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/key.c b/key.c index 45f9b9e4..77f89b5c 100644 --- a/key.c +++ b/key.c @@ -28,8 +28,9 @@ #include #include "structs.h" +#include "luaa.h" #include "common/xutil.h" -#include "common/tokenize.h" +#include "common/luaobject.h" /** Grab key on a window. * \param win The window. diff --git a/key.h b/key.h index ef973c2c..dcadbb7b 100644 --- a/key.h +++ b/key.h @@ -22,7 +22,7 @@ #ifndef AWESOME_KEY_H #define AWESOME_KEY_H -#include "luaa.h" +#include "common/luaobject.h" typedef struct keyb_t { diff --git a/keygrabber.c b/keygrabber.c index c5b33bb2..be6c6573 100644 --- a/keygrabber.c +++ b/keygrabber.c @@ -24,6 +24,7 @@ #include "structs.h" #include "keygrabber.h" #include "key.h" +#include "luaa.h" #include "common/xutil.h" /** Grab the keyboard. diff --git a/luaa.c b/luaa.c index a5bef8f7..32e89629 100644 --- a/luaa.c +++ b/luaa.c @@ -51,8 +51,6 @@ extern const struct luaL_reg awesome_hooks_lib[]; extern const struct luaL_reg awesome_keygrabber_lib[]; extern const struct luaL_reg awesome_mousegrabber_lib[]; extern const struct luaL_reg awesome_root_lib[]; -extern const struct luaL_reg awesome_image_methods[]; -extern const struct luaL_reg awesome_image_meta[]; extern const struct luaL_reg awesome_mouse_methods[]; extern const struct luaL_reg awesome_mouse_meta[]; extern const struct luaL_reg awesome_screen_methods[]; @@ -737,8 +735,7 @@ luaA_init(xdgHandle* xdg) button_class_setup(L); /* Export image */ - luaA_class_setup(L, &image_class, "image", (lua_class_allocator_t) image_new, - awesome_image_methods, awesome_image_meta); + image_class_setup(L); /* Export tag */ tag_class_setup(L); diff --git a/luaa.h b/luaa.h index f9e342da..62389dba 100644 --- a/luaa.h +++ b/luaa.h @@ -30,6 +30,7 @@ #include #include "draw.h" +#include "common/lualib.h" #define luaA_deprecate(L, repl) \ luaA_warn(L, "%s: This function is deprecated and will be removed, see %s", \ diff --git a/mouse.c b/mouse.c index 64f6c2f4..24acf569 100644 --- a/mouse.c +++ b/mouse.c @@ -24,6 +24,7 @@ #include "client.h" #include "structs.h" #include "wibox.h" +#include "luaa.h" #include "common/tokenize.h" #include "common/xutil.h" diff --git a/mousegrabber.c b/mousegrabber.c index 8d12f9b7..90cb2c2d 100644 --- a/mousegrabber.c +++ b/mousegrabber.c @@ -1,7 +1,7 @@ /* * mousegrabber.c - mouse pointer grabbing * - * Copyright © 2008 Julien Danjou + * Copyright © 2008-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include "structs.h" #include "mouse.h" #include "mousegrabber.h" +#include "luaa.h" #include "common/xcursor.h" #include "common/xutil.h" diff --git a/property.c b/property.c index e5e88623..1773fb07 100644 --- a/property.c +++ b/property.c @@ -26,9 +26,10 @@ #include "client.h" #include "ewmh.h" #include "wibox.h" +#include "window.h" +#include "luaa.h" #include "common/atoms.h" #include "common/xutil.h" -#include "window.h" void property_update_wm_transient_for(client_t *c, xcb_get_property_reply_t *reply) diff --git a/root.c b/root.c index 91161406..88cef01f 100644 --- a/root.c +++ b/root.c @@ -24,6 +24,7 @@ #include "structs.h" #include "button.h" #include "wibox.h" +#include "luaa.h" #include "common/xcursor.h" #include "common/tokenize.h" #include "common/xutil.h" diff --git a/screen.c b/screen.c index 2ef532d0..a6c092cf 100644 --- a/screen.c +++ b/screen.c @@ -30,6 +30,7 @@ #include "client.h" #include "widget.h" #include "wibox.h" +#include "luaa.h" #include "common/xutil.h" static inline area_t diff --git a/structs.h b/structs.h index b741b0f4..a866562a 100644 --- a/structs.h +++ b/structs.h @@ -25,11 +25,14 @@ #define SN_API_NOT_YET_FROZEN #include +#include + #include #include #include "config.h" #include "key.h" +#include "draw.h" #include "common/xembed.h" typedef struct wibox_t wibox_t; diff --git a/tag.c b/tag.c index dbfa3217..92c63aec 100644 --- a/tag.c +++ b/tag.c @@ -24,6 +24,7 @@ #include "client.h" #include "ewmh.h" #include "widget.h" +#include "luaa.h" /** Tag type */ struct tag diff --git a/timer.c b/timer.c index f3acc28d..6f8f7f60 100644 --- a/timer.c +++ b/timer.c @@ -24,6 +24,7 @@ #include "structs.h" #include "luaa.h" #include "timer.h" +#include "common/luaobject.h" typedef struct { diff --git a/titlebar.c b/titlebar.c index 2e376934..f18ec280 100644 --- a/titlebar.c +++ b/titlebar.c @@ -1,7 +1,7 @@ /* * titlebar.c - titlebar management * - * Copyright © 2008 Julien Danjou + * Copyright © 2008-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include "widget.h" #include "wibox.h" #include "screen.h" +#include "luaa.h" /** Get a client by its titlebar. * \param titlebar The titlebar. diff --git a/wibox.c b/wibox.c index 905cbd84..ce3adf16 100644 --- a/wibox.c +++ b/wibox.c @@ -27,6 +27,7 @@ #include "client.h" #include "screen.h" #include "window.h" +#include "luaa.h" #include "common/xcursor.h" #include "common/xutil.h" diff --git a/wibox.h b/wibox.h index 6c17e402..432d79db 100644 --- a/wibox.h +++ b/wibox.h @@ -23,6 +23,7 @@ #define AWESOME_WIBOX_H #include "widget.h" +#include "common/luaobject.h" /** Wibox types */ typedef enum diff --git a/widget.c b/widget.c index 25b8f2c7..144658aa 100644 --- a/widget.c +++ b/widget.c @@ -29,6 +29,7 @@ #include "widget.h" #include "wibox.h" #include "client.h" +#include "luaa.h" #include "common/atoms.h" #include "common/xutil.h" diff --git a/widgets/graph.c b/widgets/graph.c index 771508a1..bad7367c 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -23,6 +23,7 @@ #include #include "widget.h" +#include "luaa.h" #include "common/tokenize.h" typedef enum diff --git a/widgets/imagebox.c b/widgets/imagebox.c index e5aedf77..ac1fcfe1 100644 --- a/widgets/imagebox.c +++ b/widgets/imagebox.c @@ -1,7 +1,7 @@ /* * imagebox.c - imagebox widget * - * Copyright © 2008 Julien Danjou + * Copyright © 2008-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ */ #include "widget.h" +#include "luaa.h" #include "titlebar.h" /** The imagebox private data structure */ diff --git a/widgets/progressbar.c b/widgets/progressbar.c index 11cfef8f..605ecd3d 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -20,8 +20,9 @@ * */ -#include "common/tokenize.h" #include "widget.h" +#include "luaa.h" +#include "common/tokenize.h" /** Progressbar bar data structure */ typedef struct diff --git a/widgets/textbox.c b/widgets/textbox.c index 175616f3..269167b4 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -21,6 +21,7 @@ #include "widget.h" #include "wibox.h" +#include "luaa.h" #include "common/tokenize.h" /** The textbox private data structure */