wibox: port to new object system

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-08-17 16:56:03 +02:00
parent a916f2cd55
commit 84839d456d
12 changed files with 954 additions and 646 deletions

View File

@ -120,3 +120,5 @@ word
word_char word_char
workarea workarea
wrap wrap
x
y

20
event.c
View File

@ -429,13 +429,9 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
wibox->mouse_over = NULL; wibox->mouse_over = NULL;
} }
if(wibox->mouse_leave) luaA_object_push(globalconf.L, wibox);
{ luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0);
luaA_object_push(globalconf.L, wibox); lua_pop(globalconf.L, 1);
luaA_object_push_item(globalconf.L, -1, wibox->mouse_leave);
lua_remove(globalconf.L, -2);
luaA_dofunction(globalconf.L, 0, 0);
}
} }
return 0; return 0;
@ -466,13 +462,9 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
if(w) if(w)
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w); event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
if(wibox->mouse_enter) luaA_object_push(globalconf.L, wibox);
{ luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 0);
luaA_object_push(globalconf.L, wibox); lua_pop(globalconf.L, 1);
luaA_object_push_item(globalconf.L, -1, wibox->mouse_enter);
lua_remove(globalconf.L, -2);
luaA_dofunction(globalconf.L, 0, 0);
}
} }
if((c = client_getbytitlebarwin(ev->event)) if((c = client_getbytitlebarwin(ev->event))

View File

@ -168,7 +168,6 @@ end
local function add_item(data, num, item_info) local function add_item(data, num, item_info)
local item = wibox({ local item = wibox({
position = "floating",
fg = data.theme.fg_normal, fg = data.theme.fg_normal,
bg = data.theme.bg_normal, bg = data.theme.bg_normal,
border_color = data.theme.border, border_color = data.theme.border,
@ -205,7 +204,7 @@ local function add_item(data, num, item_info)
local mouse_enter_func = function () item_enter(data, num, true) end local mouse_enter_func = function () item_enter(data, num, true) end
label:add_signal("mouse::enter", mouse_enter_func) label:add_signal("mouse::enter", mouse_enter_func)
item.mouse_enter = mouse_enter_func item:add_signal("mouse::enter", mouse_enter_func)
-- Create the submenu icon widget -- Create the submenu icon widget
local submenu local submenu
@ -294,12 +293,10 @@ function show(menu, keygrabber)
set_coords(menu, screen_index) set_coords(menu, screen_index)
for num, item in pairs(menu.items) do for num, item in pairs(menu.items) do
local wibox = item.wibox local wibox = item.wibox
wibox:geometry({ wibox.width = menu.w
width = menu.w, wibox.height = menu.h
height = menu.h, wibox.x = menu.x
x = menu.x, wibox.y = menu.y + (num - 1) * (menu.h - menu.theme.border_width)
y = menu.y + (num - 1) * (menu.h + menu.theme.border_width)
})
wibox.screen = screen_index wibox.screen = screen_index
end end

View File

@ -273,21 +273,19 @@ end
--- Move the wibox under the cursor --- Move the wibox under the cursor
--@param w The wibox to move, or none to use that under the pointer --@param w The wibox to move, or none to use that under the pointer
function wibox.move(w) function wibox.move(w)
if not w then w = wibox_under_pointer() end local w = w or wibox_under_pointer()
if not w then return end if not w then return end
local offset = { local offset = {
x = w:geometry()["x"] - capi.mouse.coords()["x"], x = w.x - capi.mouse.coords().x,
y = w:geometry()["y"] - capi.mouse.coords()["y"] y = w.y - capi.mouse.coords().y
} }
capi.mousegrabber.run(function (mouse) capi.mousegrabber.run(function (mouse)
local button_down = false local button_down = false
if awibox.get_position(w) == "floating" then if awibox.get_position(w) == "floating" then
w:geometry({ w.x = capi.mouse.coords().x + offset.x
x = capi.mouse.coords()["x"] + offset["x"], w.y = capi.mouse.coords().y + offset.y
y = capi.mouse.coords()["y"] + offset["y"],
})
else else
local wa = awibox.get_workarea(capi.mouse.screen) local wa = awibox.get_workarea(capi.mouse.screen)

View File

@ -36,15 +36,15 @@ function get_workarea(s)
for _, wprop in ipairs(wiboxes) do for _, wprop in ipairs(wiboxes) do
if wprop.wibox.visible and wprop.wibox.screen == s then if wprop.wibox.visible and wprop.wibox.screen == s then
if wprop.position == "top" then if wprop.position == "top" then
area.y = area.y + wprop.wibox:geometry().height + (2 * wprop.wibox.border_width) area.y = area.y + wprop.wibox.height + (2 * wprop.wibox.border_width)
area.height = area.height - (wprop.wibox:geometry().height + (2 * wprop.wibox.border_width)) area.height = area.height - (wprop.wibox.height + (2 * wprop.wibox.border_width))
elseif wprop.position == "bottom" then elseif wprop.position == "bottom" then
area.height = area.height - (wprop.wibox:geometry().height + (2 * wprop.wibox.border_width)) area.height = area.height - (wprop.wibox.height + (2 * wprop.wibox.border_width))
elseif wprop.position == "left" then elseif wprop.position == "left" then
area.x = area.x + (wprop.wibox:geometry().width + (2 * wprop.wibox.border_width)) area.x = area.x + wprop.wibox.width + (2 * wprop.wibox.border_width)
area.width = area.width - (wprop.wibox:geometry().width + (2 * wprop.wibox.border_width)) area.width = area.width - (wprop.wibox.width + (2 * wprop.wibox.border_width))
elseif wprop.position == "right" then elseif wprop.position == "right" then
area.width = area.width - (wprop.wibox:geometry().width + (2 * wprop.wibox.border_width)) area.width = area.width - (wprop.wibox.width + (2 * wprop.wibox.border_width))
end end
end end
end end
@ -62,19 +62,19 @@ local function compute_area(wibox, position, s)
and not (ignore and wprop.position == position) then and not (ignore and wprop.position == position) then
if (wprop.position == "right" or wprop.position == "left") if (wprop.position == "right" or wprop.position == "left")
and wprop.position == position then and wprop.position == position then
area.x = area.x + (wibox:geometry().width + (2 * wibox.border_width)) area.x = area.x + (wibox.width + (2 * wibox.border_width))
elseif wprop.position == "top" then elseif wprop.position == "top" then
if position == "top" then if position == "top" then
area.y = area.y + (wprop.wibox:geometry().height + (2 * wprop.wibox.border_width)) area.y = area.y + (wprop.wibox.height + (2 * wprop.wibox.border_width))
elseif position == "left" or position == "right" then elseif position == "left" or position == "right" then
area.height = area.height - (wprop.wibox:geometry().height + (2 * wprop.wibox.border_width)) area.height = area.height - (wprop.wibox.height + (2 * wprop.wibox.border_width))
area.y = area.y + (wprop.wibox:geometry().height + (2 * wprop.wibox.border_width)) area.y = area.y + (wprop.wibox.height + (2 * wprop.wibox.border_width))
end end
elseif wprop.position == "bottom" then elseif wprop.position == "bottom" then
if position == "bottom" then if position == "bottom" then
area.y = area.y - (wprop.wibox:geometry().height + (2 * wprop.wibox.border_width)) area.y = area.y - (wprop.wibox.height + (2 * wprop.wibox.border_width))
elseif position == "left" or position == "right" then elseif position == "left" or position == "right" then
area.height = area.height - (wprop.wibox:geometry().height + (2 * wprop.wibox.border_width)) area.height = area.height - (wprop.wibox.height + (2 * wprop.wibox.border_width))
end end
end end
end end
@ -102,19 +102,17 @@ end
function set_position(wibox, position, screen) function set_position(wibox, position, screen)
local area = compute_area(wibox, position, screen) local area = compute_area(wibox, position, screen)
local wingeom = wibox:geometry()
-- The "length" of a wibox is always chosen to be the optimal size -- The "length" of a wibox is always chosen to be the optimal size
-- (non-floating). -- (non-floating).
-- The "width" of a wibox is kept if it exists. -- The "width" of a wibox is kept if it exists.
if position == "right" then if position == "right" then
wingeom.x = area.x + area.width - (wingeom.width + 2 * wibox.border_width) wibox.x = area.x + area.width - (wibox.width + 2 * wibox.border_width)
elseif position == "left" then elseif position == "left" then
wingeom.x = area.x wibox.x = area.x
elseif position == "bottom" then elseif position == "bottom" then
wingeom.y = (area.y + area.height) - (wingeom.height + 2 * wibox.border_width) wibox.y = (area.y + area.height) - (wibox.height + 2 * wibox.border_width)
elseif position == "top" then elseif position == "top" then
wingeom.y = area.y wibox.y = area.y
end end
for _, wprop in ipairs(wiboxes) do for _, wprop in ipairs(wiboxes) do
@ -123,8 +121,6 @@ function set_position(wibox, position, screen)
break break
end end
end end
wibox:geometry(wingeom)
end end
-- Reset all wiboxes positions. -- Reset all wiboxes positions.
@ -180,49 +176,40 @@ end
function align(wibox, align, screen) function align(wibox, align, screen)
local position = get_position(wibox) local position = get_position(wibox)
local area = compute_area(wibox, position, screen) local area = compute_area(wibox, position, screen)
local wingeom = wibox:geometry()
wingeom.height = wingeom.height + 2 * wibox.border_width
wingeom.width = wingeom.width + 2 * wibox.border_width
if position == "right" then if position == "right" then
if align == "right" then if align == "right" then
wingeom.y = area.y wibox.y = area.y
elseif align == "left" then elseif align == "left" then
wingeom.y = area.y + area.height - wingeom.height wibox.y = area.y + area.height - (wibox.height + 2 * wibox.border_width)
elseif align == "center" then elseif align == "center" then
wingeom.y = area.y + (area.height - wingeom.height) / 2 wibox.y = area.y + (area.height - wibox.height) / 2
end end
elseif position == "left" then elseif position == "left" then
if align == "right" then if align == "right" then
wingeom.y = (area.y + area.height) - wingeom.height wibox.y = (area.y + area.height) - (wibox.height + 2 * wibox.border_width)
elseif align == "left" then elseif align == "left" then
wingeom.y = area.y wibox.y = area.y
elseif align == "center" then elseif align == "center" then
wingeom.y = area.y + (area.height - wingeom.height) / 2 wibox.y = area.y + (area.height - wibox.height) / 2
end end
elseif position == "bottom" then elseif position == "bottom" then
if align == "right" then if align == "right" then
wingeom.x = area.x + area.width - wingeom.width wibox.x = area.x + area.width - (wibox.width + 2 * wibox.border_width)
elseif align == "left" then elseif align == "left" then
wingeom.x = area.x wibox.x = area.x
elseif align == "center" then elseif align == "center" then
wingeom.x = area.x + (area.width - wingeom.width) / 2 wibox.x = area.x + (area.width - wibox.width) / 2
end end
elseif position == "top" then elseif position == "top" then
if align == "right" then if align == "right" then
wingeom.x = area.x + area.width - wingeom.width wibox.x = area.x + area.width - (wibox.width + 2 * wibox.border_width)
elseif align == "left" then elseif align == "left" then
wingeom.x = area.x wibox.x = area.x
elseif align == "center" then elseif align == "center" then
wingeom.x = area.x + (area.width - wingeom.width) / 2 wibox.x = area.x + (area.width - wibox.width) / 2
end end
end end
-- Reset height and width
wingeom.height = wingeom.height - 2 * wibox.border_width
wingeom.width = wingeom.width - 2 * wibox.border_width
wibox:geometry(wingeom)
end end
--- Stretch a wibox so it takes all screen width or height. --- Stretch a wibox so it takes all screen width or height.
@ -230,14 +217,11 @@ end
function stretch(wibox) function stretch(wibox)
local position = get_position(wibox) local position = get_position(wibox)
local area = compute_area(wibox, position) local area = compute_area(wibox, position)
local wingeom = {}
if position == "right" or position == "left" then if position == "right" or position == "left" then
wingeom.height = area.height - (2 * wibox.border_width) wibox.height = area.height - (2 * wibox.border_width)
wibox:geometry(wingeom)
align(wibox, "center") align(wibox, "center")
else else
wingeom.width = area.width - (2 * wibox.border_width) wibox.width = area.width - (2 * wibox.border_width)
wibox:geometry(wingeom)
align(wibox, "left") align(wibox, "left")
end end
end end
@ -341,20 +325,17 @@ end
-- @param corner_size The size in pixel of the rounded corners. -- @param corner_size The size in pixel of the rounded corners.
function rounded_corners(wibox, corner_size) function rounded_corners(wibox, corner_size)
local border = wibox.border_width local border = wibox.border_width
local geometry = wibox:geometry()
local width = geometry.width
local height = geometry.height
-- Corners can't be larger than half the wibox' space -- Corners can't be larger than half the wibox' space
if width / 2 < corner_size then if wibox.width / 2 < corner_size then
corner_size = width / 2 corner_size = wibox.width / 2
end end
if height / 2 < corner_size then if wibox.height / 2 < corner_size then
corner_size = height / 2 corner_size = wibox.height / 2
end end
wibox.shape_clip = do_rounded_corners(width, height, corner_size) wibox.shape_clip = do_rounded_corners(wibox.width, wibox.height, corner_size)
wibox.shape_bounding = do_rounded_corners(width + border * 2, height + border * 2, corner_size + border) wibox.shape_bounding = do_rounded_corners(wibox.width + border * 2, wibox.height + border * 2, corner_size + border)
end end
local function update_wiboxes_position(obj, prop) local function update_wiboxes_position(obj, prop)

View File

@ -62,11 +62,11 @@ local shots = { }
local enemies = { } local enemies = { }
function player.new () function player.new ()
p = wibox({ bg = gamedata.solidbg or "#12345600" }) p = wibox({ bg = gamedata.solidbg or "#12345600",
p:geometry({ width = 24, width = 24,
height = 16, height = 16,
x = gamedata.field.x + (gamedata.field.w / 2), x = gamedata.field.x + (gamedata.field.w / 2),
y = gamedata.field.y + gamedata.field.h - (16 + 5) }) y = gamedata.field.y + gamedata.field.h - (16 + 5) })
p.screen = gamedata.screen p.screen = gamedata.screen
w = widget({ type = "imagebox" }) w = widget({ type = "imagebox" })
@ -78,32 +78,28 @@ end
function player.move(x) function player.move(x)
if not gamedata.running then return false end if not gamedata.running then return false end
local g = gamedata.player:geometry()
if x < 0 and g.x > gamedata.field.x then if x < 0 and gamedata.player.x > gamedata.field.x then
g.x = g.x + x gamedata.player.x = gamedata.player.x + x
elseif x > 0 and g.x < gamedata.field.x + gamedata.field.w - 30 then elseif x > 0 and gamedata.player.x < gamedata.field.x + gamedata.field.w - 30 then
g.x = g.x + x gamedata.player.x = gamedata.player.x + x
end end
gamedata.player:geometry(g)
end end
function player.fire() function player.fire()
if not gamedata.running then return false end if not gamedata.running then return false end
if gamedata.ammo == 1 then if gamedata.ammo == 1 then
gamedata.ammo = 0 gamedata.ammo = 0
local gb = gamedata.player:geometry() shots.fire(gamedata.player.x + 9, gamedata.player.y - 10, "#00FF00")
shots.fire(gb.x + 9, gb.y - 10, "#00FF00")
end end
end end
function shots.fire (x, y, color) function shots.fire (x, y, color)
local s = wibox({ bg = color }) local s = wibox({ bg = color,
s:geometry({ width = 4, width = 4,
height = 10, height = 10,
x = x, x = x,
y = y }) y = y })
s.screen = gamedata.screen s.screen = gamedata.screen
if not gamedata.shot or gamedata.shot.screen == nil then if not gamedata.shot or gamedata.shot.screen == nil then
@ -114,11 +110,11 @@ end
function shots.fire_enemy (x, y, color) function shots.fire_enemy (x, y, color)
if gamedata.enemies.shots.fired < gamedata.enemies.shots.max then if gamedata.enemies.shots.fired < gamedata.enemies.shots.max then
gamedata.enemies.shots.fired = gamedata.enemies.shots.fired + 1 gamedata.enemies.shots.fired = gamedata.enemies.shots.fired + 1
local s = wibox({ bg = color }) local s = wibox({ bg = color,
s:geometry({ width = 4, width = 4,
height = 10, height = 10,
x = x, x = x,
y = y }) y = y })
s.screen = gamedata.screen s.screen = gamedata.screen
for i = 1, gamedata.enemies.shots.max do for i = 1, gamedata.enemies.shots.max do
if not gamedata.enemies.shots[i] or gamedata.enemies.shots[i].screen == nil then if not gamedata.enemies.shots[i] or gamedata.enemies.shots[i].screen == nil then
@ -136,13 +132,11 @@ function shots.handle()
local s = gamedata.shot local s = gamedata.shot
if s and s.screen then if s and s.screen then
gamedata.ammo = 0 gamedata.ammo = 0
local g = s:geometry() if s.y < gamedata.field.y + 15 then
if g.y < gamedata.field.y + 15 then
s.screen = nil s.screen = nil
gamedata.ammo = 1 gamedata.ammo = 1
else else
g.y = g.y - 6 s.y = s.y - 6
s:geometry(g)
end end
end end
end end
@ -155,13 +149,11 @@ function shots.handle_enemy ()
for i = 1, gamedata.enemies.shots.max do for i = 1, gamedata.enemies.shots.max do
local s = gamedata.enemies.shots[i] local s = gamedata.enemies.shots[i]
if s and s.screen then if s and s.screen then
local g = s:geometry() if s.y > gamedata.field.y + gamedata.field.h - 15 then
if g.y > gamedata.field.y + gamedata.field.h - 15 then
s.screen = nil s.screen = nil
gamedata.enemies.shots.fired = gamedata.enemies.shots.fired - 1 gamedata.enemies.shots.fired = gamedata.enemies.shots.fired - 1
else else
g.y = g.y + 3 s.y = s.y + 3
s:geometry(g)
end end
if game.collide(gamedata.player, s) then if game.collide(gamedata.player, s) then
game.over() game.over()
@ -171,11 +163,11 @@ function shots.handle_enemy ()
end end
function enemies.new (t) function enemies.new (t)
e = wibox({ bg = gamedata.solidbg or "#12345600" }) e = wibox({ bg = gamedata.solidbg or "#12345600",
e:geometry({ height = gamedata.enemies.h, height = gamedata.enemies.h,
width = gamedata.enemies.w, width = gamedata.enemies.w,
x = gamedata.field.x, x = gamedata.field.x,
y = gamedata.field.y }) y = gamedata.field.y })
e.screen = gamedata.screen e.screen = gamedata.screen
w = widget({ type = "imagebox" }) w = widget({ type = "imagebox" })
w.image = gamedata.enemies[t] w.image = gamedata.enemies[t]
@ -222,13 +214,11 @@ function enemies.handle ()
for x = 1, #gamedata.enemies.data[y] do for x = 1, #gamedata.enemies.data[y] do
local e = gamedata.enemies.data[y][x] local e = gamedata.enemies.data[y][x]
if e.screen then if e.screen then
local g = e:geometry()
gamedata.enemies.number = gamedata.enemies.number + 1 gamedata.enemies.number = gamedata.enemies.number + 1
if gamedata.enemies.speed_count == (gamedata.enemies.speed - 1) then if gamedata.enemies.speed_count == (gamedata.enemies.speed - 1) then
g.y = math.floor(gamedata.field.y + gamedata.enemies.y + ((y - 1) * gamedata.enemies.h * 2)) e.y = math.floor(gamedata.field.y + gamedata.enemies.y + ((y - 1) * gamedata.enemies.h * 2))
g.x = math.floor(gamedata.field.x + gamedata.enemies.x + ((x - 1) * gamedata.enemies.w * 2)) e.x = math.floor(gamedata.field.x + gamedata.enemies.x + ((x - 1) * gamedata.enemies.w * 2))
e:geometry(g) if game.collide(gamedata.player, e) or e.y > gamedata.field.y + gamedata.field.h - 20 then
if game.collide(gamedata.player, e) or g.y > gamedata.field.y + gamedata.field.h - 20 then
game.over() game.over()
end end
end end
@ -316,12 +306,9 @@ function keyhandler(mod, key, event)
end end
function game.collide(o1, o2) function game.collide(o1, o2)
g1 = o1:geometry()
g2 = o2:geometry()
--check if o2 is inside o1 --check if o2 is inside o1
if g2.x >= g1.x and g2.x <= g1.x + g1.width if o2.x >= o1.x and o2.x <= o1.x + o1.width
and g2.y >= g1.y and g2.y <= g1.y + g1.height then and o2.y >= o1.y and o2.y <= o1.y + o1.height then
return true return true
end end
@ -441,11 +428,11 @@ function game.highscore (score)
end end
gamedata.highscore.window = wibox({ bg = gamedata.btheme.bg_focus or "#333333", gamedata.highscore.window = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
fg = gamedata.btheme.fg_focus or "#FFFFFF" }) fg = gamedata.btheme.fg_focus or "#FFFFFF",
gamedata.highscore.window:geometry({ height = 20, height = 20,
width = 300, width = 300,
x = gamedata.field.x + math.floor(gamedata.field.w / 2) - 150, x = gamedata.field.x + math.floor(gamedata.field.w / 2) - 150,
y = gamedata.field.y + math.floor(gamedata.field.h / 2) }) y = gamedata.field.y + math.floor(gamedata.field.h / 2) })
gamedata.highscore.window.screen = gamedata.screen gamedata.highscore.window.screen = gamedata.screen
gamedata.namebox = widget({ type = "textbox" }) gamedata.namebox = widget({ type = "textbox" })
@ -487,11 +474,11 @@ function run(args)
gamedata.cachedir = awful.util.getdir("cache") gamedata.cachedir = awful.util.getdir("cache")
if gamedata.solidbg then if gamedata.solidbg then
gamedata.field.background = wibox({ bg = gamedata.solidbg }) gamedata.field.background = wibox({ bg = gamedata.solidbg,
gamedata.field.background:geometry({ x = gamedata.field.x, x = gamedata.field.x,
y = gamedata.field.y, y = gamedata.field.y,
height = gamedata.field.h, height = gamedata.field.h,
width = gamedata.field.w }) width = gamedata.field.w })
gamedata.field.background.screen = gamedata.screen gamedata.field.background.screen = gamedata.screen
end end
@ -502,11 +489,11 @@ function run(args)
gamedata.field.caption.text = " Awesome Invaders" gamedata.field.caption.text = " Awesome Invaders"
gamedata.field.north = wibox({ bg = gamedata.btheme.bg_focus or "#333333", gamedata.field.north = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
fg = gamedata.btheme.fg_focus or "#FFFFFF" }) fg = gamedata.btheme.fg_focus or "#FFFFFF",
gamedata.field.north:geometry({ width = gamedata.field.w + 10, width = gamedata.field.w + 10,
height = gamedata.field.caption:extents()["height"], height = gamedata.field.caption:extents()["height"],
x = gamedata.field.x - 5, x = gamedata.field.x - 5,
y = gamedata.field.y - gamedata.field.caption:extents()["height"] }) y = gamedata.field.y - gamedata.field.caption:extents()["height"] })
gamedata.field.north.screen = gamedata.screen gamedata.field.north.screen = gamedata.screen
gamedata.field.north.widgets = { gamedata.field.north.widgets = {
@ -522,27 +509,27 @@ function run(args)
} }
gamedata.field.south = wibox({ bg = gamedata.btheme.bg_focus or "#333333", gamedata.field.south = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
fg = gamedata.btheme.fg_focus or "#FFFFFF" }) fg = gamedata.btheme.fg_focus or "#FFFFFF",
gamedata.field.south:geometry({ width = gamedata.field.w, width = gamedata.field.w,
height = 5, height = 5,
x = gamedata.field.x, x = gamedata.field.x,
y = gamedata.field.y + gamedata.field.h - 5 }) y = gamedata.field.y + gamedata.field.h - 5 })
gamedata.field.south.screen = gamedata.screen gamedata.field.south.screen = gamedata.screen
gamedata.field.west = wibox({ bg = gamedata.btheme.bg_focus or "#333333", gamedata.field.west = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
fg = gamedata.btheme.fg_focus or "#FFFFFF" }) fg = gamedata.btheme.fg_focus or "#FFFFFF",
gamedata.field.west:geometry({ width = 5, width = 5,
height = gamedata.field.h, height = gamedata.field.h,
x = gamedata.field.x - 5, x = gamedata.field.x - 5,
y = gamedata.field.y }) y = gamedata.field.y })
gamedata.field.west.screen = gamedata.screen gamedata.field.west.screen = gamedata.screen
gamedata.field.east = wibox({ bg = gamedata.btheme.bg_focus or "#333333", gamedata.field.east = wibox({ bg = gamedata.btheme.bg_focus or "#333333",
fg = gamedata.btheme.fg_focus or "#FFFFFF" }) fg = gamedata.btheme.fg_focus or "#FFFFFF",
gamedata.field.east:geometry({ width = 5, width = 5,
height = gamedata.field.h, height = gamedata.field.h,
x = gamedata.field.x + gamedata.field.w, x = gamedata.field.x + gamedata.field.w,
y = gamedata.field.y }) y = gamedata.field.y })
gamedata.field.east.screen = gamedata.screen gamedata.field.east.screen = gamedata.screen
gamedata.enemies.speed = 5 gamedata.enemies.speed = 5

5
luaa.c
View File

@ -57,8 +57,6 @@ extern const struct luaL_reg awesome_screen_methods[];
extern const struct luaL_reg awesome_screen_meta[]; extern const struct luaL_reg awesome_screen_meta[];
extern const struct luaL_reg awesome_client_methods[]; extern const struct luaL_reg awesome_client_methods[];
extern const struct luaL_reg awesome_client_meta[]; extern const struct luaL_reg awesome_client_meta[];
extern const struct luaL_reg awesome_wibox_methods[];
extern const struct luaL_reg awesome_wibox_meta[];
/** Quit awesome. /** Quit awesome.
* \param L The Lua VM state. * \param L The Lua VM state.
@ -741,8 +739,7 @@ luaA_init(xdgHandle* xdg)
tag_class_setup(L); tag_class_setup(L);
/* Export wibox */ /* Export wibox */
luaA_class_setup(L, &wibox_class, "wibox", (lua_class_allocator_t) wibox_new, wibox_class_setup(L);
awesome_wibox_methods, awesome_wibox_meta);
/* Export widget */ /* Export widget */
widget_class_setup(L); widget_class_setup(L);

View File

@ -568,7 +568,11 @@ property_handle_net_wm_opacity(void *data __attribute__ ((unused)),
wibox_t *wibox = wibox_getbywin(window); wibox_t *wibox = wibox_getbywin(window);
if(wibox) if(wibox)
wibox->opacity = window_opacity_get_from_reply(reply); {
luaA_object_push(globalconf.L, wibox);
wibox_set_opacity(globalconf.L, -1, window_opacity_get_from_reply(reply));
lua_pop(globalconf.L, -1);
}
else else
{ {
client_t *c = client_getbywin(window); client_t *c = client_getbywin(window);

View File

@ -85,7 +85,7 @@ void
titlebar_unban(wibox_t *titlebar) titlebar_unban(wibox_t *titlebar)
{ {
/* Do this manually because the system doesn't know we moved the toolbar. /* Do this manually because the system doesn't know we moved the toolbar.
* Note that !isvisible titlebars are unmapped and for fullscreen it'll * Note that !visible titlebars are unmapped and for fullscreen it'll
* end up offscreen anyway. */ * end up offscreen anyway. */
if(titlebar && titlebar->isbanned) if(titlebar && titlebar->isbanned)
{ {
@ -279,9 +279,9 @@ titlebar_client_attach(client_t *c)
void void
titlebar_set_visible(wibox_t *t, bool visible) titlebar_set_visible(wibox_t *t, bool visible)
{ {
if(visible != t->isvisible) if(visible != t->visible)
{ {
if((t->isvisible = visible)) if((t->visible = visible))
titlebar_unban(t); titlebar_unban(t);
else else
titlebar_ban(t); titlebar_ban(t);
@ -291,112 +291,77 @@ titlebar_set_visible(wibox_t *t, bool visible)
} }
} }
/** Titlebar newindex.
* \param L The Lua VM state.
* \param titlebar The wibox titlebar.
* \param tok The attribute token.
* \return The number of elements pushed on stack.
*/
int int
luaA_titlebar_newindex(lua_State *L, wibox_t *titlebar, awesome_token_t tok) luaA_titlebar_set_position(lua_State *L, int udx)
{ {
client_t *c = NULL; wibox_t *titlebar = luaA_checkudata(L, udx, &wibox_class);
size_t len;
switch(tok) const char *buf = luaL_checklstring(L, -1, &len);
position_t position = position_fromstr(buf, len);
if(position != titlebar->position)
{ {
position_t position; switch(position)
int i;
size_t len;
const char *buf;
case A_TK_ALIGN:
if((buf = luaL_checklstring(L, 3, &len)))
titlebar->align = draw_align_fromstr(buf, len);
else
return 0;
break;
case A_TK_BORDER_WIDTH:
if((i = luaL_checknumber(L, 3)) >= 0)
wibox_border_width_set(titlebar, i);
else
return 0;
break;
case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init_reply(xcolor_init_unchecked(&titlebar->border.color, buf, len)))
wibox_border_color_set(titlebar, &titlebar->border.color);
return 0;
case A_TK_POSITION:
buf = luaL_checklstring(L, 3, &len);
position = position_fromstr(buf, len);
if(position != titlebar->position)
{ {
switch(position) case Left:
switch(titlebar->position)
{ {
int tmp;
case Left: case Left:
switch(titlebar->position)
{
int tmp;
case Left:
case Right:
break;
case Top:
case Bottom:
tmp = titlebar->geometry.width;
titlebar->geometry.width = titlebar->geometry.height;
titlebar->geometry.height = tmp;
break;
}
wibox_orientation_set(titlebar, North);
break;
case Right: case Right:
switch(titlebar->position)
{
int tmp;
case Left:
case Right:
break;
case Top:
case Bottom:
tmp = titlebar->geometry.width;
titlebar->geometry.width = titlebar->geometry.height;
titlebar->geometry.height = tmp;
break;
}
wibox_orientation_set(titlebar, South);
break; break;
case Top: case Top:
case Bottom: case Bottom:
switch(titlebar->position) tmp = titlebar->geometry.width;
{ titlebar->geometry.width = titlebar->geometry.height;
int tmp; titlebar->geometry.height = tmp;
case Left:
case Right:
tmp = titlebar->geometry.width;
titlebar->geometry.width = titlebar->geometry.height;
titlebar->geometry.height = tmp;
break;
case Top:
case Bottom:
break;
}
wibox_orientation_set(titlebar, East);
break; break;
} }
titlebar->position = position; wibox_set_orientation(L, udx, North);
if((c = client_getbytitlebar(titlebar))) break;
case Right:
switch(titlebar->position)
{ {
titlebar_update_geometry(c); int tmp;
/* call geometry hook for client because some like to case Left:
* set titlebar width in that hook, which make sense */ case Right:
hook_property(c, "geometry"); break;
case Top:
case Bottom:
tmp = titlebar->geometry.width;
titlebar->geometry.width = titlebar->geometry.height;
titlebar->geometry.height = tmp;
break;
} }
wibox_set_orientation(L, udx, South);
break;
case Top:
case Bottom:
switch(titlebar->position)
{
int tmp;
case Left:
case Right:
tmp = titlebar->geometry.width;
titlebar->geometry.width = titlebar->geometry.height;
titlebar->geometry.height = tmp;
break;
case Top:
case Bottom:
break;
}
wibox_set_orientation(L, udx, East);
break;
}
titlebar->position = position;
client_t *c;
if((c = client_getbytitlebar(titlebar)))
{
titlebar_update_geometry(c);
/* call geometry hook for client because some like to
* set titlebar width in that hook, which make sense */
hook_property(c, "geometry");
} }
break;
default:
return 0;
} }
return 0; return 0;
} }

View File

@ -36,7 +36,7 @@ void titlebar_set_visible(wibox_t *, bool);
void titlebar_ban(wibox_t *); void titlebar_ban(wibox_t *);
void titlebar_unban(wibox_t *); void titlebar_unban(wibox_t *);
int luaA_titlebar_newindex(lua_State *, wibox_t *, awesome_token_t); int luaA_titlebar_set_position(lua_State *, int);
static inline bool static inline bool
titlebar_isvisible(client_t *c, screen_t *screen) titlebar_isvisible(client_t *c, screen_t *screen)
@ -45,7 +45,7 @@ titlebar_isvisible(client_t *c, screen_t *screen)
{ {
if(c->isfullscreen) if(c->isfullscreen)
return false; return false;
if(!c->titlebar || !c->titlebar->isvisible) if(!c->titlebar || !c->titlebar->visible)
return false; return false;
return true; return true;
} }
@ -65,7 +65,7 @@ titlebar_geometry_add(wibox_t *t, int border, area_t geometry)
* This can then be substracted/added to the witdh/height/x/y. * This can then be substracted/added to the witdh/height/x/y.
* In this case the border is included, because it belongs to a different window. * In this case the border is included, because it belongs to a different window.
*/ */
if(t && t->isvisible) if(t && t->visible)
switch(t->position) switch(t->position)
{ {
case Top: case Top:
@ -106,7 +106,7 @@ titlebar_geometry_remove(wibox_t *t, int border, area_t geometry)
* This can then be substracted/added to the witdh/height/x/y. * This can then be substracted/added to the witdh/height/x/y.
* In this case the border is included, because it belongs to a different window. * In this case the border is included, because it belongs to a different window.
*/ */
if(t && t->isvisible) if(t && t->visible)
switch(t->position) switch(t->position)
{ {
case Top: case Top:
@ -147,7 +147,10 @@ titlebar_update_geometry(client_t *c)
/* Client geometry without titlebar, but including borders, since that is always consistent. */ /* Client geometry without titlebar, but including borders, since that is always consistent. */
titlebar_geometry_compute(c, titlebar_geometry_remove(c->titlebar, 0, c->geometry), &geom); titlebar_geometry_compute(c, titlebar_geometry_remove(c->titlebar, 0, c->geometry), &geom);
wibox_moveresize(c->titlebar, geom); luaA_object_push(globalconf.L, c);
luaA_object_push_item(globalconf.L, -1, c->titlebar);
wibox_moveresize(globalconf.L, -1, geom);
lua_pop(globalconf.L, 2);
} }
#endif #endif

1120
wibox.c

File diff suppressed because it is too large Load Diff

26
wibox.h
View File

@ -39,7 +39,7 @@ struct wibox_t
/** Ontop */ /** Ontop */
bool ontop; bool ontop;
/** Visible */ /** Visible */
bool isvisible; bool visible;
/** Position */ /** Position */
position_t position; position_t position;
/** Wibox type */ /** Wibox type */
@ -53,8 +53,6 @@ struct wibox_t
void *widgets_table; void *widgets_table;
/** Widget the mouse is over */ /** Widget the mouse is over */
widget_t *mouse_over; widget_t *mouse_over;
/** Mouse over event handler */
void *mouse_enter, *mouse_leave;
/** Need update */ /** Need update */
bool need_update; bool need_update;
/** Need shape update */ /** Need shape update */
@ -75,14 +73,10 @@ struct wibox_t
xcb_gcontext_t gc; xcb_gcontext_t gc;
/** The window geometry. */ /** The window geometry. */
area_t geometry; area_t geometry;
/** The window border */ /** The window border width */
struct uint16_t border_width;
{ /** The window border color */
/** The window border width */ xcolor_t border_color;
uint16_t width;
/** The window border color */
xcolor_t color;
} border;
/** Draw context */ /** Draw context */
draw_context_t ctx; draw_context_t ctx;
/** Orientation */ /** Orientation */
@ -109,16 +103,16 @@ void luaA_wibox_invalidate_byitem(lua_State *, const void *);
wibox_t * wibox_getbywin(xcb_window_t); wibox_t * wibox_getbywin(xcb_window_t);
void wibox_moveresize(wibox_t *, area_t); void wibox_moveresize(lua_State *, int, area_t);
void wibox_refresh_pixmap_partial(wibox_t *, int16_t, int16_t, uint16_t, uint16_t); void wibox_refresh_pixmap_partial(wibox_t *, int16_t, int16_t, uint16_t, uint16_t);
void wibox_init(wibox_t *, int); void wibox_init(wibox_t *, int);
void wibox_wipe(wibox_t *); void wibox_wipe(wibox_t *);
void wibox_border_width_set(wibox_t *, uint32_t); void wibox_set_opacity(lua_State *, int, double);
void wibox_border_color_set(wibox_t *, const xcolor_t *); void wibox_set_orientation(lua_State *, int, orientation_t);
void wibox_orientation_set(wibox_t *, orientation_t);
void wibox_class_setup(lua_State *);
lua_class_t wibox_class; lua_class_t wibox_class;
LUA_OBJECT_FUNCS(wibox_class, wibox_t, wibox)
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80