Skip to content

Commit

Permalink
Added password field style options
Browse files Browse the repository at this point in the history
  • Loading branch information
Guff committed Jan 16, 2012
1 parent 4fe6043 commit a6c336a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
23 changes: 21 additions & 2 deletions clib/style.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

void style_set(const gchar *font, gint x, gint y, gint off_x, gint off_y,
gint width, gint height, gdouble r, gdouble g, gdouble b,
gdouble a) {
gdouble a, const gchar *bg, const gchar *border,
gdouble border_width) {
if (font) {
pango_font_description_free(lualock.style.font_desc);
lualock.style.font_desc = pango_font_description_from_string(font);
Expand All @@ -41,6 +42,18 @@ void style_set(const gchar *font, gint x, gint y, gint off_x, gint off_y,
lualock.style.b = b;
lualock.style.a = a;

GdkRGBA bg_color, border_color;

gdk_rgba_parse(&bg_color, bg ? bg : "white");

lualock.style.bg_color = bg_color;

gdk_rgba_parse(&border_color, border ? border : "rgba(0, 0, 0, 0.6)");

lualock.style.border_color = border_color;

lualock.style.border_width = border_width;

cairo_surface_t *old_pw_surface = lualock.pw_surface;
lualock.pw_surface = create_surface(width, height);
cairo_surface_destroy(old_pw_surface);
Expand All @@ -58,6 +71,9 @@ int lualock_lua_style_set(lua_State *L) {
lua_getfield(L, 1, "off_y");
lua_getfield(L, 1, "width");
lua_getfield(L, 1, "height");
lua_getfield(L, 1, "bg_color");
lua_getfield(L, 1, "border_color");
lua_getfield(L, 1, "border_width");

style_set(luaL_optstring(L, 2, DEFAULT_FONT),
luaL_optnumber(L, 3, lualock.style.x),
Expand All @@ -66,7 +82,10 @@ int lualock_lua_style_set(lua_State *L) {
luaL_optnumber(L, 6, lualock.style.off_y),
luaL_optnumber(L, 7, lualock.style.width),
luaL_optnumber(L, 8, lualock.style.height),
r, g, b, a);
r, g, b, a,
lua_tostring(L, 9),
lua_tostring(L, 10),
luaL_optnumber(L, 11, lualock.style.border_width));
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion config/rc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ local oocairo = require "oocairo"

-- {{{ lualock settings
style{ color = "#333333", font = "Sans 12", x = 500, y = 400, off_x = 5,
off_y = 6, width = 150, height = 24 }
off_y = 6, width = 150, height = 24, bg_color = 'rgba(255, 255, 255, 1)',
border_color = 'rgba(0, 0, 0, 0.6)', border_width = 2 }

prefs{ timeout = 10 * 60 }
-- }}}
Expand Down
6 changes: 3 additions & 3 deletions drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ void draw_password_field(cairo_t *cr) {
cairo_rectangle(cr, 0, 0, lualock.style.width,
lualock.style.height);
cairo_clip_preserve(cr);
cairo_set_source_rgb(cr, 1, 1, 1);
gdk_cairo_set_source_rgba(cr, &lualock.style.bg_color);
cairo_fill_preserve(cr);
cairo_set_source_rgba(cr, 0, 0, 0, .6);
cairo_set_line_width(cr, 2.0);
gdk_cairo_set_source_rgba(cr, &lualock.style.border_color);
cairo_set_line_width(cr, lualock.style.border_width);
cairo_stroke(cr);
}

Expand Down
1 change: 1 addition & 0 deletions lualock.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static void init_style(void) {
lualock.style.g = 0;
lualock.style.b = 0;
lualock.style.a = 1;
lualock.style.border_width = 2;
}

static void init_cairo(void) {
Expand Down
4 changes: 4 additions & 0 deletions lualock.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ typedef struct {
gdouble g;
gdouble b;
gdouble a;

GdkRGBA bg_color;
GdkRGBA border_color;
gdouble border_width;
} style_t;

typedef struct {
Expand Down

0 comments on commit a6c336a

Please sign in to comment.