diff --git a/awesomerc.lua.in b/awesomerc.lua.in index 99df8798..d0c3c27b 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -170,7 +170,7 @@ for s = 1, screen.count() do end, mytasklist.buttons) -- Create the wibox - mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal }) + mywibox[s] = awful.wibox({ position = "top", screen = s }) -- Add widgets to the wibox - order matters mywibox[s].widgets = { mylauncher, mytaglist[s], @@ -179,7 +179,6 @@ for s = 1, screen.count() do mytextbox, mylayoutbox[s], s == 1 and mysystray or nil } - mywibox[s].screen = s end -- }}} diff --git a/client.c b/client.c index 8b2b4d8b..bb20a355 100644 --- a/client.c +++ b/client.c @@ -215,10 +215,6 @@ client_ban(client_t *c) c->isbanned = true; - /* All the wiboxes (may) need to be repositioned. */ - if(client_hasstrut(c)) - wibox_update_positions(); - if(globalconf.screens.tab[c->phys_screen].prev_client_focus == c) globalconf.screens.tab[c->phys_screen].prev_client_focus = NULL; @@ -683,7 +679,7 @@ client_resize(client_t *c, area_t geometry, bool hints) area_t area; /* offscreen appearance fixes */ - area = display_area_get(c->phys_screen, NULL); + area = display_area_get(c->phys_screen); if(geometry.x > area.width) geometry.x = area.width - geometry.width; @@ -814,7 +810,7 @@ client_setfullscreen(client_t *c, bool s) client_setabove(c, false); client_setontop(c, false); - geometry = screen_area_get(c->screen, NULL, false); + geometry = screen_area_get(c->screen, false); c->geometries.fullscreen = c->geometry; c->border_fs = c->border; client_setborder(c, 0); @@ -848,9 +844,7 @@ client_setmaxhoriz(client_t *c, bool s) /* remove fullscreen mode */ client_setfullscreen(c, false); - geometry = screen_area_get(c->screen, - &c->screen->wiboxes, - true); + geometry = screen_area_get(c->screen, true); geometry.y = c->geometry.y; geometry.height = c->geometry.height; c->geometries.max.x = c->geometry.x; @@ -887,9 +881,7 @@ client_setmaxvert(client_t *c, bool s) /* remove fullscreen mode */ client_setfullscreen(c, false); - geometry = screen_area_get(c->screen, - &c->screen->wiboxes, - true); + geometry = screen_area_get(c->screen, true); geometry.x = c->geometry.x; geometry.width = c->geometry.width; c->geometries.max.y = c->geometry.y; @@ -1020,10 +1012,6 @@ client_unban(client_t *c) request); c->isbanned = false; - - /* All the wiboxes (may) need to be repositioned. */ - if(client_hasstrut(c)) - wibox_update_positions(); } } @@ -1085,10 +1073,6 @@ client_unmanage(client_t *c) ewmh_update_net_client_list(c->phys_screen); - /* All the wiboxes (may) need to be repositioned. */ - if(client_hasstrut(c)) - wibox_update_positions(); - /* set client as invalid */ c->invalid = true; @@ -1436,7 +1420,7 @@ luaA_client_struts(lua_State *L) if(lua_gettop(L) == 2) { strut_t struts; - area_t screen_area = display_area_get(c->phys_screen, NULL); + area_t screen_area = display_area_get(c->phys_screen); struts.left = luaA_getopt_number(L, 2, "left", c->strut.left); struts.right = luaA_getopt_number(L, 2, "right", c->strut.right); @@ -1461,8 +1445,6 @@ luaA_client_struts(lua_State *L) ewmh_update_client_strut(c); client_need_arrange(c); - /* All the wiboxes (may) need to be repositioned. */ - wibox_update_positions(); hook_property(client, c, "struts"); } diff --git a/common/util.c b/common/util.c index 39824dda..3c89e519 100644 --- a/common/util.c +++ b/common/util.c @@ -114,8 +114,6 @@ position_fromstr(const char *pos, ssize_t len) return Right; case A_TK_LEFT: return Left; - case A_TK_FLOATING: - return Floating; } } @@ -132,7 +130,6 @@ position_tostr(position_t p) case Bottom: return "bottom"; case Right: return "right"; case Left: return "left"; - case Floating: return "floating"; default: return NULL; } } diff --git a/common/util.h b/common/util.h index 9e84e197..d8f42028 100644 --- a/common/util.h +++ b/common/util.h @@ -38,7 +38,7 @@ typedef enum { - East, + East = 0, South, North, } orientation_t; @@ -46,11 +46,10 @@ typedef enum /** A list of possible position, not sex related */ typedef enum { - Top, + Top = 0, Bottom, Right, - Left, - Floating + Left } position_t; /** Link a name to a function */ diff --git a/event.c b/event.c index d9f84a27..16d5491f 100644 --- a/event.c +++ b/event.c @@ -280,12 +280,7 @@ event_handle_configurerequest(void *data __attribute__ ((unused)), geometry = titlebar_geometry_add(c->titlebar, c->border, geometry); if(client_resize(c, geometry, false)) - { - /* All the wiboxes (may) need to be repositioned. */ - if(client_hasstrut(c)) - wibox_update_positions(); client_need_arrange(c); - } else { /* Resize wasn't officially needed, but we don't want to break expectations. */ diff --git a/ewmh.c b/ewmh.c index 950f764e..7dd0aace 100644 --- a/ewmh.c +++ b/ewmh.c @@ -45,9 +45,7 @@ static void ewmh_update_desktop_geometry(int phys_screen) { - area_t geom = screen_area_get(&globalconf.screens.tab[phys_screen], - NULL, - false); + area_t geom = screen_area_get(&globalconf.screens.tab[phys_screen], false); uint32_t sizes[] = { geom.width, geom.height }; xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, @@ -231,10 +229,7 @@ ewmh_update_workarea(int phys_screen) { tag_array_t *tags = &globalconf.screens.tab[phys_screen].tags; uint32_t *area = p_alloca(uint32_t, tags->len * 4); - area_t geom = screen_area_get(&globalconf.screens.tab[phys_screen], - &globalconf.screens.tab[phys_screen].wiboxes, - true); - + area_t geom = screen_area_get(&globalconf.screens.tab[phys_screen], true); for(int i = 0; i < tags->len; i++) { @@ -634,8 +629,6 @@ ewmh_process_client_strut(client_t *c, xcb_get_property_reply_t *strut_r) c->strut.bottom_end_x = strut[11]; client_need_arrange(c); - /* All the wiboxes (may) need to be repositioned. */ - wibox_update_positions(); hook_property(client, c, "struts"); } diff --git a/lib/awful/init.lua.in b/lib/awful/init.lua.in index 5093689a..d5644ef6 100644 --- a/lib/awful/init.lua.in +++ b/lib/awful/init.lua.in @@ -20,6 +20,7 @@ require("awful.mouse") require("awful.remote") require("awful.key") require("awful.button") +require("awful.wibox") require("awful.startup_notification") --- AWesome Functions very UsefuL diff --git a/lib/awful/layout/init.lua.in b/lib/awful/layout/init.lua.in index 3bff6014..5d972d35 100644 --- a/lib/awful/layout/init.lua.in +++ b/lib/awful/layout/init.lua.in @@ -11,6 +11,7 @@ local tag = require("awful.tag") local util = require("awful.util") local suit = require("awful.layout.suit") local client = require("awful.client") +local wibox = require("awful.wibox") local ascreen = require("awful.screen") local capi = { @@ -64,7 +65,7 @@ end local function on_arrange (screen) local t = tag.selected(screen) local p = {} - p.workarea = capi.screen[screen].workarea + p.workarea = wibox.get_workarea(screen) -- Handle padding local padding = ascreen.padding(screen) if padding then @@ -97,6 +98,9 @@ hooks.property.register(function (c, prop) on_arrange(c.screen) end end) +hooks.wibox_position.register(function(wibox) + on_arrange(wibox.screen) +end) hooks.padding.register(function(screen) on_arrange(screen) end) diff --git a/lib/awful/menu.lua.in b/lib/awful/menu.lua.in index 24f98bb5..9f8f40af 100644 --- a/lib/awful/menu.lua.in +++ b/lib/awful/menu.lua.in @@ -23,6 +23,7 @@ local capi = local util = require("awful.util") local tags = require("awful.tag") local awbeautiful = require("beautiful") +local awibox = require("awful.wibox") local tonumber = tonumber --- Menu module for awful @@ -249,7 +250,7 @@ function clients(menu) end local function set_coords(menu, screen_idx) - local s_geometry = capi.screen[screen_idx].workarea + local s_geometry = awibox.get_workarea(screen_idx) local screen_w = s_geometry.x + s_geometry.width local screen_h = s_geometry.y + s_geometry.height diff --git a/lib/awful/mouse.lua.in b/lib/awful/mouse.lua.in index 6a309392..fc4cb900 100644 --- a/lib/awful/mouse.lua.in +++ b/lib/awful/mouse.lua.in @@ -10,6 +10,7 @@ local tag = require("awful.tag") local hooks = require("awful.hooks") local aclient = require("awful.client") local widget = require("awful.widget") +local awibox = require("awful.wibox") local util = require("awful.util") local type = type local math = math @@ -114,7 +115,7 @@ function client.snap(c, snap, x, y, fixed_x, fixed_y) geom.y = y or geom.y geom, edge = snap_inside(geom, capi.screen[c.screen].geometry, snap) - geom = snap_inside(geom, capi.screen[c.screen].workarea, snap) + geom = snap_inside(geom, awibox.get_workarea(c.screen), snap) -- Allow certain windows to snap to the edge of the workarea. -- Only allow docking to workarea for consistency/to avoid problems. @@ -240,7 +241,7 @@ function client.dragtotag.border(c) for _, v in ipairs(mouse.buttons) do if v then button_down = true end end - local wa = capi.screen[c.screen].workarea + local wa = awibox.get_workarea(c.screen) if mouse.x >= wa.x + wa.width then capi.mouse.coords({ x = wa.x + wa.width - 1 }) elseif mouse.x <= wa.x then @@ -289,7 +290,7 @@ function wibox.move(w) y = capi.mouse.coords()["y"] + offset["y"], }) else - local wa = capi.screen[capi.mouse.screen].workarea + local wa = awibox.get_workarea(capi.mouse.screen) if capi.mouse.coords()["y"] > wa.y + wa.height - 10 then w.position = "bottom" @@ -362,7 +363,7 @@ local function client_resize_magnifier(c, corner) local corner, x, y = client.corner(c, corner) capi.mouse.coords({ x = x, y = y }) - local wa = capi.screen[c.screen].workarea + local wa = awibox.get_workarea(c.screen) local center_x = wa.x + wa.width / 2 local center_y = wa.y + wa.height / 2 local maxdist_pow = (wa.width^2 + wa.height^2) / 4 @@ -385,7 +386,7 @@ local function client_resize_magnifier(c, corner) end local function client_resize_tiled(c, lay) - local wa = capi.screen[c.screen].workarea + local wa = awibox.get_workarea(c.screen) local mwfact = tag.getmwfact() local cursor local g = c:geometry() diff --git a/lib/awful/placement.lua.in b/lib/awful/placement.lua.in index debbe892..dbfb5d78 100644 --- a/lib/awful/placement.lua.in +++ b/lib/awful/placement.lua.in @@ -17,6 +17,7 @@ local capi = } local client = require("awful.client") local layout = require("awful.layout") +local wibox = require("awful.wibox") --- Placement module for awful module("awful.placement") @@ -105,7 +106,7 @@ end function no_offscreen(c) local c = c or capi.client.focus local geometry = c:geometry() - local screen_geometry = capi.screen[c.screen].workarea + local screen_geometry = wibox.get_workarea(c.screen) if geometry.x + geometry.width > screen_geometry.x + screen_geometry.width then geometry.x = screen_geometry.x + screen_geometry.width - geometry.width @@ -127,7 +128,7 @@ end function no_overlap(c) local cls = client.visible(c.screen) local curlay = layout.get() - local areas = { capi.screen[c.screen].workarea } + local areas = { wibox.get_workarea(c.screen) } local geometry = c:geometry() for i, cl in pairs(cls) do if cl ~= c and (client.floating.get(cl) or curlay == layout.suit.floating) then diff --git a/lib/awful/wibox.lua.in b/lib/awful/wibox.lua.in new file mode 100644 index 00000000..190caeaa --- /dev/null +++ b/lib/awful/wibox.lua.in @@ -0,0 +1,284 @@ +--------------------------------------------------------------------------- +-- @author Julien Danjou <julien@danjou.info> +-- @copyright 2009 Julien Danjou +-- @release @AWESOME_VERSION@ +--------------------------------------------------------------------------- + +-- Grab environment we need +local capi = +{ + awesome = awesome, + screen = screen, + wibox = wibox +} +local setmetatable = setmetatable +local ipairs = ipairs +local table = table +local type = type +local hooks = require("awful.hooks") + +--- Wibox module for awful. +module("awful.wibox") + +-- Array of table with wiboxes inside. +-- It's an array so it is ordered. +local wiboxes = {} + +hooks.user.create("wibox_position") + +--- Get the workarea space without wiboxes geometry. +-- @param s The screen number. +-- @return The screen workarea. +function get_workarea(s) + local area = capi.screen[s].workarea + for _, wprop in ipairs(wiboxes) do + if wprop.wibox.visible and wprop.wibox.screen == s then + if wprop.position == "top" then + area.y = area.y + wprop.wibox:geometry().height + area.height = area.height - wprop.wibox:geometry().height + elseif wprop.position == "bottom" then + area.height = area.height - wprop.wibox:geometry().height + elseif wprop.position == "left" then + area.x = area.x + wprop.wibox:geometry().width + area.width = area.width - wprop.wibox:geometry().width + elseif wprop.position == "right" then + area.width = area.width - wprop.wibox:geometry().width + end + end + end + return area +end + +local function compute_area(wibox, position, s) + local s = wibox.screen or s or 1 + local area = capi.screen[s].workarea + local ignore = false + for _, wprop in ipairs(wiboxes) do + if wprop.wibox == wibox then + ignore = true + elseif wprop.wibox.visible and wprop.wibox.screen == s + and not (ignore and wprop.position == position) then + if (wprop.position == "right" or wprop.position == "left") + and wprop.position == position then + area.x = area.x + wibox:geometry().width + elseif wprop.position == "top" then + if position == "top" then + area.y = area.y + wprop.wibox:geometry().height + elseif position == "left" or position == "right" then + area.height = area.height - wprop.wibox:geometry().height + area.y = area.y + wprop.wibox:geometry().height + end + elseif wprop.position == "bottom" then + if position == "bottom" then + area.y = area.y - wprop.wibox:geometry().height + elseif position == "left" or position == "right" then + area.height = area.height - wprop.wibox:geometry().height + end + end + end + end + return area +end + +--- Get a wibox position if it has been set, or return top. +-- @param wibox The wibox +-- @return The wibox position. +function get_position(wibox) + for _, wprop in ipairs(wiboxes) do + if wprop.wibox == wibox then + return wprop.position + end + end + return "top" +end + +--- Attach a wibox to a screen at the position. +-- @param wibox The wibox to attach. +-- @param position The position: top, bottom left or right. +-- @param screen If the wibox it not attached to a screen, specified on which +-- screen the position should be set. +function set_position(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 + -- (non-floating). + -- The "width" of a wibox is kept if it exists. + if position == "right" then + wingeom.x = area.x + area.width - wingeom.width + elseif position == "left" then + wingeom.x = area.x + elseif position == "bottom" then + wingeom.y = (area.y + area.height) - wingeom.height + elseif position == "top" then + wingeom.y = area.y + end + + wibox:geometry(wingeom) +end + +-- Reset all wiboxes positions. +local function update_all_wiboxes_position() + for _, wprop in ipairs(wiboxes) do + set_position(wprop.wibox, wprop.position) + hooks.user.call("wibox_position", wprop.wibox) + end +end + +--- Attach a wibox to a screen. +-- If a wibox is attached, it will be automatically be moved when other wiboxes +-- will be attached. +-- @param wibox The wibox to attach. +-- @param position The position of the wibox: top, bottom, left or right. +function attach(wibox, position) + -- Store wibox as attached in a weak-valued table + local wibox_prop_table + -- Start from end since we sometimes remove items + for i = #wiboxes, 1, -1 do + -- Since wiboxes are stored as weak value, they can disappear. + -- If they did, remove their entries + if wiboxes[i].wibox == nil then + table.remove(wiboxes, i) + elseif wiboxes[i].wibox == wibox then + wibox_prop_table = wiboxes[i] + -- We could break here, but well, let's check if there is no other + -- table with their wiboxes been garbage collected. + end + end + + if not wibox_prop_table then + table.insert(wiboxes, + setmetatable({ wibox = wibox, position = position }, { __mode = 'v' })) + else + wibox_prop_table.position = position + end + + if wibox.screen and wibox.visible then + update_all_wiboxes_position() + end +end + +--- Align a wibox. +-- @param wibox The wibox. +-- @param align The alignment: left, right or center. +-- @param screen If the wibox is not attached to any screen, you can specify the +-- screen where to align. Otherwise 1 is assumed. +function align(wibox, align, screen) + local position = get_position(wibox) + local area = compute_area(wibox, position, screen) + local wingeom = wibox:geometry() + + if position == "right" then + if align == "right" then + wingeom.y = area.y + elseif align == "left" then + wingeom.y = area.y + area.height - wingeom.height + elseif align == "center" then + wingeom.y = area.y + (area.height - wingeom.height) / 2 + end + elseif position == "left" then + if align == "right" then + wingeom.y = (area.y + area.height) - wingeom.height + elseif align == "left" then + wingeom.y = area.y + elseif align == "center" then + wingeom.y = area.y + (area.height - wingeom.height) / 2 + end + elseif position == "bottom" then + if align == "right" then + wingeom.x = area.x + area.width - wingeom.width + elseif align == "left" then + wingeom.x = area.x + elseif align == "center" then + wingeom.x = area.x + (area.width - wingeom.width) / 2 + end + elseif position == "top" then + if align == "right" then + wingeom.x = area.x + area.width - wingeom.width + elseif align == "left" then + wingeom.x = area.x + elseif align == "center" then + wingeom.x = area.x + (area.width - wingeom.width) / 2 + end + end + + wibox:geometry(wingeom) +end + +--- Stretch a wibox so it takes all screen width or height. +-- @param wibox The wibox. +function stretch(wibox) + local position = get_position(wibox) + local area = compute_area(wibox, position) + local wingeom = {} + if position == "right" or position == "left" then + wingeom.height = area.height + wibox:geometry(wingeom) + align(wibox, "center") + else + wingeom.width = area.width + wibox:geometry(wingeom) + align(wibox, "left") + end +end + +--- Create a new wibox and attach it to a screen edge. +-- @see capi.wibox +-- @param args A table with standard arguments to wibox() creator. +-- You can add also position key with value top, bottom, left or right. +-- You can also set the screen key with a screen number to attach the wibox. +-- If not specified, 1 is assumed. +-- @return The wibox created. +function new(arg) + local screen = screen or 1 + local arg = arg or {} + local position = arg.position or "top" + -- Empty position and align in arg so we are passing deprecation warning + arg.position = nil + + local w = capi.wibox(arg) + + if position == "left" then + w.orientation = "north" + w:geometry({ width = capi.awesome.font_height * 1.5 }) + elseif position == "right" then + w.orientation = "south" + w:geometry({ width = capi.awesome.font_height * 1.5 }) + end + + w.screen = arg.screen or 1 + + attach(w, position) + stretch(w) + + return w +end + +local function update_wiboxes_position(obj, prop) + if (type(obj) == "wibox" + and (prop == nil + or prop == "visible" + or prop == "screen")) + or (type(obj) == "client" + and prop == "struts") then + update_all_wiboxes_position() + end +end + +local function update_wiboxes_on_struts(c) + local struts = c:struts() + if struts.left ~= 0 or struts.right ~= 0 + or struts.top ~= 0 or struts.bottom ~= 0 then + update_all_wiboxes_position() + end +end + +-- Hook registered to reset all wiboxes position. +hooks.property.register(update_wiboxes_position) +hooks.manage.register(update_wiboxes_on_struts) +hooks.unmanage.register(update_wiboxes_on_struts) + +setmetatable(_M, { __call = function(_, ...) return new(...) end }) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/lib/invaders.lua.in b/lib/invaders.lua.in index 301ae986..25a256ab 100644 --- a/lib/invaders.lua.in +++ b/lib/invaders.lua.in @@ -61,8 +61,7 @@ local shots = { } local enemies = { } function player.new () - p = wibox({ position = "floating", - bg = gamedata.solidbg or "#12345600" }) + p = wibox({ bg = gamedata.solidbg or "#12345600" }) p:geometry({ width = 24, height = 16, x = gamedata.field.x + (gamedata.field.w / 2), @@ -99,8 +98,7 @@ function player.fire() end function shots.fire (x, y, color) - local s = wibox({ position = "floating", - bg = color }) + local s = wibox({ bg = color }) s:geometry({ width = 4, height = 10, x = x, @@ -115,8 +113,7 @@ end function shots.fire_enemy (x, y, color) if gamedata.enemies.shots.fired < gamedata.enemies.shots.max then gamedata.enemies.shots.fired = gamedata.enemies.shots.fired + 1 - local s = wibox({ position = "floating", - bg = color }) + local s = wibox({ bg = color }) s:geometry({ width = 4, height = 10, x = x, @@ -173,8 +170,7 @@ function shots.handle_enemy () end function enemies.new (t) - e = wibox({ position = "floating", - bg = gamedata.solidbg or "#12345600" }) + e = wibox({ bg = gamedata.solidbg or "#12345600" }) e:geometry({ height = gamedata.enemies.h, width = gamedata.enemies.w, x = gamedata.field.x, @@ -443,8 +439,7 @@ function game.highscore (score) if s <= score then newentry = true end end - gamedata.highscore.window = wibox({ position = "floating", - 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" }) gamedata.highscore.window:geometry({ height = 20, width = 300, @@ -491,8 +486,7 @@ function run(args) gamedata.cachedir = awful.util.getdir("cache") if gamedata.solidbg then - gamedata.field.background = wibox({ position = "floating", - bg = gamedata.solidbg }) + gamedata.field.background = wibox({ bg = gamedata.solidbg }) gamedata.field.background:geometry({ x = gamedata.field.x, y = gamedata.field.y, height = gamedata.field.h, @@ -500,8 +494,7 @@ function run(args) gamedata.field.background.screen = gamedata.screen end - gamedata.field.north = wibox({ position = "floating", - 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" }) gamedata.field.north:geometry({ width = gamedata.field.w + 10, height = 15, @@ -519,8 +512,7 @@ function run(args) gamedata.field.north.widgets = { gamedata.field.caption, gamedata.field.status } - gamedata.field.south = wibox({ position = "floating", - 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" }) gamedata.field.south:geometry({ width = gamedata.field.w, height = 5, @@ -528,8 +520,7 @@ function run(args) y = gamedata.field.y + gamedata.field.h - 5 }) gamedata.field.south.screen = gamedata.screen - gamedata.field.west = wibox({ position = "floating", - 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" }) gamedata.field.west:geometry({ width = 5, height = gamedata.field.h, @@ -537,8 +528,7 @@ function run(args) y = gamedata.field.y }) gamedata.field.west.screen = gamedata.screen - gamedata.field.east = wibox({ position = "floating", - 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" }) gamedata.field.east:geometry({ width = 5, height = gamedata.field.h, diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in index 85af99f7..7be4a818 100644 --- a/lib/naughty.lua.in +++ b/lib/naughty.lua.in @@ -18,6 +18,7 @@ local capi = { screen = screen, local hooks = require("awful.hooks") local button = require("awful.button") local util = require("awful.util") +local wibox = require("awful.wibox") local bt = require("beautiful") --- Notification library @@ -118,7 +119,7 @@ end -- @param width Popup width (optional) -- @return Absolute position and index in { x = X, y = Y, idx = I } table local function get_offset(screen, position, idx, width, height) - local ws = capi.screen[screen].workarea + local ws = wibox.get_workarea(screen) local v = {} local idx = idx or #notifications[screen][position] + 1 local width = width or notifications[screen][position][idx].width @@ -344,8 +345,7 @@ function notify(args) end -- create container wibox - notification.box = capi.wibox({ position = "floating", - fg = fg, + notification.box = capi.wibox({ fg = fg, bg = bg, border_color = border_color, border_width = border_width }) @@ -365,11 +365,12 @@ function notify(args) end -- crop to workarea size if too big - if width > capi.screen[screen].workarea.width - 2 * (border_width or 0) - 2 * (config.padding or 0) then - width = capi.screen[screen].workarea.width - 2 * (border_width or 0) - 2 * (config.padding or 0) + local workarea = wibox.get_workarea(screen) + if width > workarea.width - 2 * (border_width or 0) - 2 * (config.padding or 0) then + width = workarea.width - 2 * (border_width or 0) - 2 * (config.padding or 0) end - if height > capi.screen[screen].workarea.height - 2 * (border_width or 0) - 2 * (config.padding or 0) then - height = capi.screen[screen].workarea.height - 2 * (border_width or 0) - 2 * (config.padding or 0) + if height > workarea.height - 2 * (border_width or 0) - 2 * (config.padding or 0) then + height = workarea.height - 2 * (border_width or 0) - 2 * (config.padding or 0) end -- set size in notification object diff --git a/lib/telak.lua.in b/lib/telak.lua.in index 10988199..6f70afe4 100644 --- a/lib/telak.lua.in +++ b/lib/telak.lua.in @@ -50,7 +50,7 @@ local function new(_, args) if not args or not args.image then return end -- Create wibox - local w = capi.wibox({ position = "floating" }) + local w = capi.wibox{} data[w] = { image = args.image } local wimg = capi.widget({ type = "imagebox" }) w.widgets = wimg diff --git a/screen.c b/screen.c index 62c9ef57..2602017e 100644 --- a/screen.c +++ b/screen.c @@ -147,7 +147,7 @@ screen_getbycoord(screen_t *screen, int x, int y) * \return The screen area. */ area_t -screen_area_get(screen_t *screen, wibox_array_t *wiboxes, bool strut) +screen_area_get(screen_t *screen, bool strut) { area_t area = screen->geometry; uint16_t top = 0, bottom = 0, left = 0, right = 0; @@ -189,31 +189,6 @@ screen_area_get(screen_t *screen, wibox_array_t *wiboxes, bool strut) } } - - if(wiboxes) - foreach(_w, *wiboxes) - { - wibox_t *w = *_w; - if(w->isvisible) - switch(w->position) - { - case Top: - top = MAX(top, (uint16_t) (w->sw.geometry.y - area.y) + w->sw.geometry.height + 2 * w->sw.border.width); - break; - case Bottom: - bottom = MAX(bottom, (uint16_t) (area.y + area.height) - w->sw.geometry.y); - break; - case Left: - left = MAX(left, (uint16_t) (w->sw.geometry.x - area.x) + w->sw.geometry.width + 2 * w->sw.border.width); - break; - case Right: - right = MAX(right, (uint16_t) (area.x + area.width) - w->sw.geometry.x); - break; - default: - break; - } - } - area.x += left; area.y += top; area.width -= left + right; @@ -224,26 +199,16 @@ screen_area_get(screen_t *screen, wibox_array_t *wiboxes, bool strut) /** Get display info. * \param phys_screen Physical screen number. - * \param wiboxes The wiboxes. * \return The display area. */ area_t -display_area_get(int phys_screen, wibox_array_t *wiboxes) +display_area_get(int phys_screen) { xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen); area_t area = { .x = 0, .y = 0, .width = s->width_in_pixels, .height = s->height_in_pixels }; - - if(wiboxes) - foreach(_w, *wiboxes) - { - wibox_t *w = *_w; - area.y += w->position == Top ? w->sw.geometry.height : 0; - area.height -= (w->position == Top || w->position == Bottom) ? w->sw.geometry.height : 0; - } - return area; } @@ -307,8 +272,8 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool dotag, bool doresiz if(!doresize) return; - from = screen_area_get(old_screen, NULL, false); - to = screen_area_get(c->screen, NULL, false); + from = screen_area_get(old_screen, false); + to = screen_area_get(c->screen, false); area_t new_geometry = c->geometry; @@ -424,7 +389,7 @@ luaA_screen_tags(lua_State *L) * \return The number of elements pushed on stack. * \luastack * \lfield coords The screen coordinates. Immutable. - * \lfield workarea The screen workarea, i.e. without wiboxes. + * \lfield workarea The screen workarea. */ static int luaA_screen_index(lua_State *L) @@ -445,7 +410,7 @@ luaA_screen_index(lua_State *L) luaA_pusharea(L, s->geometry); break; case A_TK_WORKAREA: - luaA_pusharea(L, screen_area_get(s, &s->wiboxes, true)); + luaA_pusharea(L, screen_area_get(s, true)); break; default: return 0; diff --git a/screen.h b/screen.h index 507213ec..08cd6624 100644 --- a/screen.h +++ b/screen.h @@ -52,8 +52,8 @@ ARRAY_FUNCS(screen_t, screen, DO_NOTHING) void screen_scan(void); screen_t *screen_getbycoord(screen_t *, int, int); -area_t screen_area_get(screen_t *, wibox_array_t *, bool); -area_t display_area_get(int, wibox_array_t *); +area_t screen_area_get(screen_t *, bool); +area_t display_area_get(int); int screen_virttophys(int); void screen_client_moveto(client_t *, screen_t *, bool, bool); diff --git a/titlebar.c b/titlebar.c index 1f21f3d5..c79a7a0a 100644 --- a/titlebar.c +++ b/titlebar.c @@ -254,8 +254,6 @@ titlebar_client_attach(client_t *c) switch(t->position) { - case Floating: - t->position = Top; case Top: case Bottom: if(!t->sw.geometry.height) @@ -363,7 +361,6 @@ luaA_titlebar_newindex(lua_State *L, wibox_t *titlebar, awesome_token_t tok) break; case Top: case Bottom: - case Floating: tmp = titlebar->sw.geometry.width; titlebar->sw.geometry.width = titlebar->sw.geometry.height; titlebar->sw.geometry.height = tmp; @@ -380,7 +377,6 @@ luaA_titlebar_newindex(lua_State *L, wibox_t *titlebar, awesome_token_t tok) break; case Top: case Bottom: - case Floating: tmp = titlebar->sw.geometry.width; titlebar->sw.geometry.width = titlebar->sw.geometry.height; titlebar->sw.geometry.height = tmp; @@ -390,7 +386,6 @@ luaA_titlebar_newindex(lua_State *L, wibox_t *titlebar, awesome_token_t tok) break; case Top: case Bottom: - case Floating: switch(titlebar->position) { int tmp; @@ -402,7 +397,6 @@ luaA_titlebar_newindex(lua_State *L, wibox_t *titlebar, awesome_token_t tok) break; case Top: case Bottom: - case Floating: break; } simplewindow_orientation_set(&titlebar->sw, East); diff --git a/wibox.c b/wibox.c index eb95ea36..5ba418e6 100644 --- a/wibox.c +++ b/wibox.c @@ -23,7 +23,6 @@ #include "wibox.h" #include "titlebar.h" #include "client.h" -#include "ewmh.h" #include "screen.h" #include "window.h" #include "common/xcursor.h" @@ -102,41 +101,6 @@ wibox_resize(wibox_t *wibox, uint16_t width, uint16_t height) wibox_need_update(wibox); } -static void -wibox_setposition(wibox_t *wibox, position_t p) -{ - if(p != wibox->position) - { - switch((wibox->position = p)) - { - case Bottom: - case Top: - case Floating: - simplewindow_orientation_set(&wibox->sw, East); - break; - case Left: - simplewindow_orientation_set(&wibox->sw, North); - break; - case Right: - simplewindow_orientation_set(&wibox->sw, South); - break; - } - /* reset width/height to 0 */ - if(wibox->position != Floating) - wibox->sw.geometry.width = wibox->sw.geometry.height = 0; - - /* recompute position */ - wibox_position_update(wibox); - - /* reset all wibox position */ - foreach(w, wibox->screen->wiboxes) - wibox_position_update(*w); - - ewmh_update_workarea(screen_virttophys(screen_array_indexof(&globalconf.screens, wibox->screen))); - - wibox_need_update(wibox); - } -} /** Kick out systray windows. * \param phys_screen Physical screen number. @@ -319,200 +283,6 @@ wibox_systray_refresh(wibox_t *wibox) } } -/* Only called by wibox_position_update() */ -static void -wibox_position_update_floating(wibox_t *wibox) -{ - area_t wingeom = wibox->sw.geometry; - - /* We only make sure the wibox is at least 1x1 pixel big. */ - wingeom.width = MAX(1, wibox->sw.geometry.width); - wingeom.height = MAX(1, wibox->sw.geometry.height); - - if(wingeom.width != wibox->sw.geometry.width - || wingeom.height != wibox->sw.geometry.height) - wibox_resize(wibox, wingeom.width, wingeom.height); -} - -/* Only called by wibox_position_update() */ -static void -wibox_position_update_non_floating(wibox_t *wibox) -{ - area_t area, wingeom = wibox->sw.geometry; - bool ignore = false; - - /* Everything we do below needs the wibox' screen. - * No screen, nothing to do. - */ - if (!wibox->screen) - return; - - /* This wibox limits the space available to clients and thus clients - * need to be repositioned. - */ - wibox->screen->need_arrange = true; - - area = screen_area_get(wibox->screen, NULL, - &wibox->screen->padding, true); - - /* Top and Bottom wibox_t have prio */ - foreach(_w, wibox->screen->wiboxes) - { - wibox_t *w = *_w; - /* Ignore every wibox after me that is in the same position */ - if(wibox == w) - { - ignore = true; - continue; - } - else if((ignore && wibox->position == w->position) || !w->isvisible) - continue; - switch(w->position) - { - case Floating: - break; - case Left: - if(wibox->position == Left) - area.x += wibox->sw.geometry.width; - break; - case Right: - if(wibox->position == Right) - area.x -= wibox->sw.geometry.width; - break; - case Top: - switch(wibox->position) - { - case Top: - area.y += w->sw.geometry.height; - break; - case Left: - case Right: - area.height -= w->sw.geometry.height; - area.y += w->sw.geometry.height; - break; - default: - break; - } - break; - case Bottom: - switch(wibox->position) - { - case Bottom: - area.y -= w->sw.geometry.height; - break; - case Left: - case Right: - area.height -= w->sw.geometry.height; - break; - default: - break; - } - break; - } - } - - /* The "length" of a wibox is always chosen to be the optimal size (non-floating). - * The "width" of a wibox is kept if it exists. - */ - switch(wibox->position) - { - case Right: - wingeom.height = area.height - 2 * wibox->sw.border.width; - wingeom.width = wibox->sw.geometry.width > 0 ? wibox->sw.geometry.width : 1.5 * globalconf.font->height; - wingeom.x = area.x + area.width - wingeom.width; - switch(wibox->align) - { - default: - wingeom.y = area.y; - break; - case AlignRight: - wingeom.y = area.y + area.height - wingeom.height; - break; - case AlignCenter: - wingeom.y = (area.y + area.height - wingeom.height) / 2; - break; - } - break; - case Left: - wingeom.height = area.height - 2 * wibox->sw.border.width; - wingeom.width = wibox->sw.geometry.width > 0 ? wibox->sw.geometry.width : 1.5 * globalconf.font->height; - wingeom.x = area.x; - switch(wibox->align) - { - default: - wingeom.y = (area.y + area.height) - wingeom.height; - break; - case AlignRight: - wingeom.y = area.y; - break; - case AlignCenter: - wingeom.y = (area.y + area.height - wingeom.height) / 2; - } - break; - case Bottom: - wingeom.height = wibox->sw.geometry.height > 0 ? wibox->sw.geometry.height : 1.5 * globalconf.font->height; - wingeom.width = area.width - 2 * wibox->sw.border.width; - wingeom.y = (area.y + area.height) - wingeom.height; - wingeom.x = area.x; - switch(wibox->align) - { - default: - break; - case AlignRight: - wingeom.x += area.width - wingeom.width; - break; - case AlignCenter: - wingeom.x += (area.width - wingeom.width) / 2; - break; - } - break; - case Top: - wingeom.height = wibox->sw.geometry.height > 0 ? wibox->sw.geometry.height : 1.5 * globalconf.font->height; - wingeom.width = area.width - 2 * wibox->sw.border.width; - wingeom.x = area.x; - wingeom.y = area.y; - switch(wibox->align) - { - default: - break; - case AlignRight: - wingeom.x += area.width - wingeom.width; - break; - case AlignCenter: - wingeom.x += (area.width - wingeom.width) / 2; - break; - } - break; - case Floating: - /* Floating wiboxes are not handled here, but in - * wibox_position_update_floating(), but the compiler insists... - */ - break; - } - - /* same window size and position ? */ - if(wingeom.width != wibox->sw.geometry.width - || wingeom.height != wibox->sw.geometry.height) - wibox_resize(wibox, wingeom.width, wingeom.height); - - if(wingeom.x != wibox->sw.geometry.x - || wingeom.y != wibox->sw.geometry.y) - wibox_move(wibox, wingeom.x, wingeom.y); -} - -/** Update the wibox position. It deletes every wibox resources and - * create them back. - * \param wibox The wibox. - */ -void -wibox_position_update(wibox_t *wibox) -{ - if(wibox->position == Floating) - wibox_position_update_floating(wibox); - else - wibox_position_update_non_floating(wibox); -} - /** Get a wibox by its window. * \param w The window id. * \return A wibox if found, NULL otherwise. @@ -570,16 +340,6 @@ wibox_refresh(void) } } -/** Reposition all wiboxes. - */ -void -wibox_update_positions(void) -{ - foreach(screen, globalconf.screens) - foreach(w, screen->wiboxes) - wibox_position_update(*w); -} - /** Set a wibox visible or not. * \param wibox The wibox. * \param v The visible value. @@ -592,7 +352,7 @@ wibox_setvisible(wibox_t *wibox, bool v) wibox->isvisible = v; wibox->mouse_over = NULL; - if(wibox->screen != NULL) + if(wibox->screen) { if(wibox->isvisible) wibox_map(wibox); @@ -601,11 +361,6 @@ wibox_setvisible(wibox_t *wibox, bool v) /* kick out systray if needed */ wibox_systray_refresh(wibox); - - /* All the other wibox and ourselves need to be repositioned */ - foreach(w, wibox->screen->wiboxes) - wibox_position_update(*w); - } hook_property(wibox, wibox, "visible"); @@ -615,10 +370,10 @@ wibox_setvisible(wibox_t *wibox, bool v) /** Remove a wibox from a screen. * \param wibox Wibox to detach from screen. */ -void +static void wibox_detach(wibox_t *wibox) { - if(wibox->screen != NULL) + if(wibox->screen) { bool v; @@ -626,8 +381,7 @@ wibox_detach(wibox_t *wibox) v = wibox->isvisible; wibox->isvisible = false; wibox_systray_refresh(wibox); - wibox_position_update(wibox); - /* restore position */ + /* restore visibility */ wibox->isvisible = v; wibox->mouse_over = NULL; @@ -676,9 +430,6 @@ wibox_attach(screen_t *s) wibox_array_append(&s->wiboxes, wibox); - /* compute x/y/width/height if not set */ - wibox_position_update(wibox); - simplewindow_init(&wibox->sw, phys_screen, wibox->sw.geometry, wibox->sw.border.width, @@ -689,13 +440,6 @@ wibox_attach(screen_t *s) simplewindow_cursor_set(&wibox->sw, xcursor_new(globalconf.connection, xcursor_font_fromstr(wibox->cursor))); - - /* All the other wibox and ourselves need to be repositioned */ - foreach(w, s->wiboxes) - wibox_position_update(*w); - - ewmh_update_workarea(phys_screen); - if(wibox->isvisible) wibox_map(wibox); else @@ -709,7 +453,7 @@ wibox_attach(screen_t *s) * * \luastack * \lparam A table with optionaly defined values: - * position, align, fg, bg, border_width, border_color, ontop, width and height. + * fg, bg, border_width, border_color, ontop, width and height. * \lreturn A brand new wibox. */ static int @@ -740,32 +484,11 @@ luaA_wibox_new(lua_State *L) w->ontop = luaA_getopt_boolean(L, 2, "ontop", false); - buf = luaA_getopt_lstring(L, 2, "align", "left", &len); - w->align = draw_align_fromstr(buf, len); - w->sw.border.width = luaA_getopt_number(L, 2, "border_width", 0); - - buf = luaA_getopt_lstring(L, 2, "position", "top", &len); - - switch((w->position = position_fromstr(buf, len))) - { - case Bottom: - case Top: - case Floating: - w->sw.orientation = East; - break; - case Left: - w->sw.orientation = North; - break; - case Right: - w->sw.orientation = South; - break; - } - w->sw.geometry.x = luaA_getopt_number(L, 2, "x", 0); w->sw.geometry.y = luaA_getopt_number(L, 2, "y", 0); - w->sw.geometry.width = luaA_getopt_number(L, 2, "width", 0); - w->sw.geometry.height = luaA_getopt_number(L, 2, "height", 0); + w->sw.geometry.width = luaA_getopt_number(L, 2, "width", 100); + w->sw.geometry.height = luaA_getopt_number(L, 2, "height", globalconf.font->height * 1.5); w->isvisible = true; w->cursor = a_strdup("left_ptr"); @@ -848,11 +571,11 @@ luaA_wibox_invalidate_byitem(lua_State *L, const void *item) * \lfield client The client attached to (titlebar). * \lfield border_width Border width. * \lfield border_color Border color. - * \lfield align The alignment. + * \lfield align The alignment (titlebar). * \lfield fg Foreground color. * \lfield bg Background color. * \lfield bg_image Background image. - * \lfield position The position. + * \lfield position The position (titlebar). * \lfield ontop On top of other windows. * \lfield cursor The mouse cursor. * \lfield visible Visibility. @@ -891,6 +614,8 @@ luaA_wibox_index(lua_State *L) luaA_pushxcolor(L, &wibox->sw.border.color); break; case A_TK_ALIGN: + if(wibox->type == WIBOX_TYPE_NORMAL) + luaA_deprecate(L, "awful.wibox.align"); lua_pushstring(L, draw_align_tostr(wibox->align)); break; case A_TK_FG: @@ -903,6 +628,8 @@ luaA_wibox_index(lua_State *L) image_push(L, wibox->bg_image); break; case A_TK_POSITION: + if(wibox->type == WIBOX_TYPE_NORMAL) + luaA_deprecate(L, "awful.wibox.attach"); lua_pushstring(L, position_tostr(wibox->position)); break; case A_TK_ONTOP: @@ -976,14 +703,7 @@ luaA_wibox_geometry(lua_State *L) wibox_resize(wibox, wingeom.width, wingeom.height); break; case WIBOX_TYPE_NORMAL: - if(wibox->position == Floating) - wibox_moveresize(wibox, wingeom); - else if(wingeom.width != wibox->sw.geometry.width - || wingeom.height != wibox->sw.geometry.height) - { - wibox_resize(wibox, wingeom.width, wingeom.height); - wibox->screen->need_arrange = true; - } + wibox_moveresize(wibox, wingeom); break; } } @@ -1028,7 +748,7 @@ luaA_wibox_newindex(lua_State *L) switch(wibox->type) { case WIBOX_TYPE_NORMAL: - wibox_position_update(wibox); + luaA_deprecate(L, "awful.wibox.align"); break; case WIBOX_TYPE_TITLEBAR: titlebar_update_geometry(client_getbytitlebar(wibox)); @@ -1038,12 +758,15 @@ luaA_wibox_newindex(lua_State *L) case A_TK_POSITION: switch(wibox->type) { - case WIBOX_TYPE_TITLEBAR: - return luaA_titlebar_newindex(L, wibox, tok); case WIBOX_TYPE_NORMAL: if((buf = luaL_checklstring(L, 3, &len))) - wibox_setposition(wibox, position_fromstr(buf, len)); + { + luaA_deprecate(L, "awful.wibox.attach"); + wibox->position = position_fromstr(buf, len); + } break; + case WIBOX_TYPE_TITLEBAR: + return luaA_titlebar_newindex(L, wibox, tok); } break; case A_TK_CLIENT: diff --git a/wibox.h b/wibox.h index 50cf3bbc..f32f2b88 100644 --- a/wibox.h +++ b/wibox.h @@ -75,13 +75,10 @@ void wibox_unref_simplified(wibox_t **); DO_ARRAY(wibox_t *, wibox, wibox_unref_simplified) void wibox_refresh(void); -void wibox_update_positions(void); void luaA_wibox_invalidate_byitem(lua_State *, const void *); -void wibox_position_update(wibox_t *); wibox_t * wibox_getbywin(xcb_window_t); -void wibox_detach(wibox_t *); static inline void wibox_moveresize(wibox_t *wibox, area_t geometry)