Skip to content

Commit

Permalink
Handle the background properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Cass committed Jul 23, 2011
1 parent 85a2228 commit 0e0631f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
14 changes: 4 additions & 10 deletions clib/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@
#include "clib/background.h"

void background_set_color(const char *hex) {
layer_t *layer = create_layer(0, 0);
add_layer(layer);
cairo_t *cr = cairo_create(layer->surface);
cairo_t *cr = cairo_create(lualock.bg_surface);

double r, g, b, a;
parse_color(hex, &r, &g, &b, &a);
cairo_set_source_rgba(cr, r, g, b, a);
cairo_paint(cr);
cairo_destroy(cr);

layer->show = TRUE;
register_update_for_layer(layer);
update_screen();
}

static int lualock_lua_background_set(lua_State *L) {
Expand All @@ -60,10 +57,7 @@ static int lualock_lua_background_set(lua_State *L) {
win_width = gdk_screen_get_width(lualock.scr);
win_height = gdk_screen_get_height(lualock.scr);

layer_t *layer = create_layer(0, 0);
add_layer(layer);

cairo_t *cr = cairo_create(layer->surface);
cairo_t *cr = cairo_create(lualock.bg_surface);

if (style) {
if (!strcmp(style, "stretch")) {
Expand All @@ -88,7 +82,7 @@ static int lualock_lua_background_set(lua_State *L) {
cairo_destroy(cr);
g_object_unref(pbuf);

layer->show = TRUE;
update_screen();

return 0;
}
Expand Down
16 changes: 10 additions & 6 deletions config/rc.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require "odious"

-- {{{ lualock settings
style{ color = "#333333", font = "Sans 12", x = 500, y = 400, off_x = 5,
off_y = 6, width = 150, height = 24 }

prefs{ timeout = 10 * 60 }
-- }}}

-- define functions for setting and restoring DPMS settings
local dpms = {
Expand All @@ -17,7 +19,7 @@ local dpms = {
return tonumber(standby) or 0, tonumber(suspend) or 0, tonumber(off) or 0
end
}

-- {{{ Hooks
-- get current DPMS settings
local standby, suspend, off = dpms.get()

Expand All @@ -30,8 +32,7 @@ hook.connect("unlock", function ()
dpms.set(standby, suspend, off)
end)

keybinder("<Alt>j", function () print("hullo") end)

-- show a dot for each failed login attempt
evildot = utils.get_data_dir() .. "/glowydot.png"
failed_attempts = 0
hook.connect("auth-failed", function ()
Expand All @@ -40,21 +41,24 @@ hook.connect("auth-failed", function ()
dot:show()
failed_attempts = failed_attempts + 1
end)
-- }}}

-- {{{
background("color", "#000000")

im = image(utils.get_data_dir() .. "/archlinux-official-light.svg")
im:scale(0.75, 0.75)
im:set_position(0.1, 0.4)
im:show()

clockbg = image(utils.get_data_dir() .. "/clockbackground.png")
clockbg:show()

user_text = text{ text = "User: " .. os.getenv("USER"), x = 500, y = 370,
font = "Anton 16", color = "#ffffff", border_color = "#000000",
border_width = 3 }
user_text:draw()

clockbg = image(utils.get_data_dir() .. "/clockbackground.png")
clockbg:show()

clock_hr = text { text = os.date("%I"), x = 55, y = 40, font = "Droid Sans Mono 110",
color = "#ffffff", border_color = "#000000", border_width = 4 }
clock_min = text { text = os.date("%M"), x = 305, y = 40, font = "Droid Sans Mono 110",
Expand Down
4 changes: 4 additions & 0 deletions drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ gboolean draw(void *data) {
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
cairo_paint(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

cairo_set_source_surface(cr, lualock.bg_surface, 0, 0);
cairo_paint(cr);

for (guint i = 0; i < lualock.layers->len; i++) {
layer_t *layer = g_ptr_array_index(lualock.layers, i);
if (!layer->show)
Expand Down
6 changes: 4 additions & 2 deletions lualock.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void init_cairo() {

lualock.pw_surface = create_surface(0, 0);

lualock.bg_surface = create_surface(0, 0);

lualock.updates_needed = cairo_region_create();
}

Expand Down Expand Up @@ -217,9 +219,9 @@ gboolean on_key_press(GdkEvent *ev) {
void event_handler(GdkEvent *ev, gpointer data) {
switch (ev->type) {
case GDK_KEY_PRESS:
// if enter was pressed, check password
if (prefs.test)
g_main_loop_quit(lualock.loop);
// if enter was pressed, check password
if (!on_key_press(ev)) {
if (authenticate_user())
g_main_loop_quit(lualock.loop);
Expand Down Expand Up @@ -282,9 +284,9 @@ void hide_lock() {
clear_timers();
clear_updates();
clear_keybinds();
gdk_window_hide(lualock.win);
gdk_keyboard_ungrab(GDK_CURRENT_TIME);
gdk_pointer_ungrab(GDK_CURRENT_TIME);
gdk_window_hide(lualock.win);
clear_layers();

clear_hooks();
Expand Down
2 changes: 2 additions & 0 deletions lualock.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ typedef struct {

cairo_surface_t *pw_surface;

cairo_surface_t *bg_surface;

GPtrArray *layers;
cairo_region_t *updates_needed;

Expand Down

0 comments on commit 0e0631f

Please sign in to comment.