From 82342f055cc5c46fecdb82b324563f428ce929a9 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 14 Mar 2016 02:21:29 -0400 Subject: [PATCH] awful.client: Deprecate .floating.get/set Begin to formalize the getter/setter syntax into a coherent one --- lib/awful/client.lua | 56 ++++++++++++++++++++++------- lib/awful/layout/suit/magnifier.lua | 3 +- lib/awful/mouse/init.lua | 8 ++--- lib/awful/placement.lua | 2 +- lib/awful/rules.lua | 5 +-- lib/awful/titlebar.lua | 2 +- lib/awful/widget/tasklist.lua | 4 ++- 7 files changed, 55 insertions(+), 25 deletions(-) diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 41feccded..cb5aa8afb 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -41,7 +41,7 @@ do __newindex = error -- Just to be sure in case anything ever does this }) end -local client = {} +local client = {object={}} -- Private data client.data = {} @@ -264,7 +264,7 @@ function client.tiled(s, stacked) local tclients = {} -- Remove floating clients for _, c in pairs(clients) do - if not client.floating.get(c) + if not client.object.get_floating(c) and not c.fullscreen and not c.maximized_vertical and not c.maximized_horizontal then @@ -599,6 +599,8 @@ function client.mark(c) end end + + --- Unmark a client and then call 'unmarked' hook. -- @client c The client to unmark, or the focused one if not specified. -- @return True if the client has been unmarked. False if the client was not marked. @@ -653,9 +655,19 @@ end --- Set a client floating state, overriding auto-detection. -- Floating client are not handled by tiling layouts. +-- @deprecated awful.client.floating.set -- @client c A client. -- @param s True or false. function client.floating.set(c, s) + util.deprecate "Use c.floating = true instead of awful.client.floating.set" + client.object.set_floating(c, s) +end + +-- Set a client floating state, overriding auto-detection. +-- Floating client are not handled by tiling layouts. +-- @client c A client. +-- @param s True or false. +function client.object.set_floating(c, s) c = c or capi.client.focus if c and client.property.get(c, "floating") ~= s then client.property.set(c, "floating", s) @@ -668,7 +680,7 @@ function client.floating.set(c, s) end local function store_floating_geometry(c) - if client.floating.get(c) then + if client.object.get_floating(c) then client.property.set(c, "floating_geometry", c:geometry()) end end @@ -703,10 +715,31 @@ end --- Get a client floating state. -- @client c A client. +-- @see floating +-- @deprecated awful.client.floating.get -- @return True or false. Note that some windows might be floating even if you -- did not set them manually. For example, windows with a type different than -- normal. function client.floating.get(c) + util.deprecate "Use c.floating instead of awful.client.floating.get" + return client.object.get_floating(c) +end + +--- The client floating state. +-- If the client is part of the tiled layout or free floating. +-- +-- Note that some windows might be floating even if you +-- did not set them manually. For example, windows with a type different than +-- normal. +-- +-- **Signal:** +-- +-- * *property::floating* +-- +-- @property floating +-- @param boolean The floating state + +function client.object.get_floating(c) c = c or capi.client.focus if c then local value = client.property.get(c, "floating") @@ -725,21 +758,20 @@ function client.floating.get(c) end --- Toggle the floating state of a client between 'auto' and 'true'. +-- Use `c.floating = not c.floating` +-- @deprecated awful.client.floating.toggle -- @client c A client. +-- @see floating function client.floating.toggle(c) c = c or capi.client.focus -- If it has been set to floating - if client.floating.get(c) then - client.floating.set(c, false) - else - client.floating.set(c, true) - end + client.object.set_floating(c, not client.object.get_floating(c)) end ---- Remove the floating information on a client. +-- Remove the floating information on a client. -- @client c The client. function client.floating.delete(c) - client.floating.set(c, nil) + client.object.set_floating(c, nil) end --- Restore (=unminimize) a random client. @@ -1127,8 +1159,8 @@ client.property.persist("floating", "boolean") -- Extend the luaobject object.properties(capi.client, { - getter_class = client, - setter_class = client, + getter_class = client.object, + setter_class = client.object, getter_fallback = client.property.get, setter_fallback = client.property.set, }) diff --git a/lib/awful/layout/suit/magnifier.lua b/lib/awful/layout/suit/magnifier.lua index 324823691..d0e460d72 100644 --- a/lib/awful/layout/suit/magnifier.lua +++ b/lib/awful/layout/suit/magnifier.lua @@ -18,7 +18,6 @@ local capi = mouse = mouse, mousegrabber = mousegrabber } -local client = require("awful.client") local magnifier = {} @@ -67,7 +66,7 @@ function magnifier.arrange(p) end -- If focused window is not tiled, take the first one which is tiled. - if client.floating.get(focus) then + if focus.floating then focus = cls[1] fidx = 1 end diff --git a/lib/awful/mouse/init.lua b/lib/awful/mouse/init.lua index 285b3aecc..a1edfdade 100644 --- a/lib/awful/mouse/init.lua +++ b/lib/awful/mouse/init.lua @@ -117,7 +117,7 @@ function mouse.client.snap(c, snap, x, y, fixed_x, fixed_y) struts['right'] = 0 struts['top'] = 0 struts['bottom'] = 0 - if edge ~= "none" and aclient.floating.get(c) then + if edge ~= "none" and c.floating then if edge == "left" or edge == "right" then struts[edge] = cur_geom.width elseif edge == "top" or edge == "bottom" then @@ -177,7 +177,7 @@ function mouse.client.move(c, snap, finished_cb) for _, v in ipairs(_mouse.buttons) do if v then local lay = layout.get(c.screen) - if lay == layout.suit.floating or aclient.floating.get(c) then + if lay == layout.suit.floating or c.floating then local x = _mouse.x - dist_x local y = _mouse.y - dist_y c:geometry(mouse.client.snap(c, snap, x, y, fixed_x, fixed_y)) @@ -195,7 +195,7 @@ function mouse.client.move(c, snap, finished_cb) end if layout.get(c.screen) ~= layout.suit.floating then local c_u_m = mouse.client_under_pointer() - if c_u_m and not aclient.floating.get(c_u_m) then + if c_u_m and not c_u_m.floating then if c_u_m ~= c then c:swap(c_u_m) end @@ -356,7 +356,7 @@ function mouse.client.resize(c, corner) local lay = layout.get(c.screen) local corner2, x, y = mouse.client.corner(c, corner) - if lay == layout.suit.floating or aclient.floating.get(c) then + if lay == layout.suit.floating or c.floating then return layout.suit.floating.mouse_resize_handler(c, corner2, x, y) elseif lay.mouse_resize_handler then return lay.mouse_resize_handler(c, corner2, x, y) diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index 9555afd88..9715b8849 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -453,7 +453,7 @@ function placement.no_overlap(c) local curlay = layout.get() local areas = { screen.workarea } for _, cl in pairs(cls) do - if cl ~= c and cl.type ~= "desktop" and (client.floating.get(cl) or curlay == layout.suit.floating) then + if cl ~= c and cl.type ~= "desktop" and (cl.floating or curlay == layout.suit.floating) then areas = area_remove(areas, area_common(cl)) end end diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index 26abc33e3..ec4dfe50a 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -13,7 +13,6 @@ local table = table local type = type local ipairs = ipairs local pairs = pairs -local aclient = require("awful.client") local atag = require("awful.tag") local rules = {} @@ -199,9 +198,7 @@ function rules.execute(c, props, callbacks) if property ~= "focus" and type(value) == "function" then value = value(c) end - if property == "floating" then - aclient.floating.set(c, value) - elseif property == "tag" then + if property == "tag" then c.screen = atag.getscreen(value) c:tags({ value }) elseif property == "switchtotag" and value and props.tag then diff --git a/lib/awful/titlebar.lua b/lib/awful/titlebar.lua index 3cb3305cc..c44d1703a 100644 --- a/lib/awful/titlebar.lua +++ b/lib/awful/titlebar.lua @@ -256,7 +256,7 @@ end --- Create a new float button for a client. -- @param c The client for which the button is wanted. function titlebar.widget.floatingbutton(c) - local widget = titlebar.widget.button(c, "floating", aclient.floating.get, aclient.floating.toggle) + local widget = titlebar.widget.button(c, "floating", aclient.object.get_floating, aclient.floating.toggle) c:connect_signal("property::floating", widget.update) return widget end diff --git a/lib/awful/widget/tasklist.lua b/lib/awful/widget/tasklist.lua index 130a6723f..1e2a51366 100644 --- a/lib/awful/widget/tasklist.lua +++ b/lib/awful/widget/tasklist.lua @@ -79,7 +79,7 @@ local function tasklist_label(c, args, tb) else if c.maximized_horizontal then name = name .. maximized_horizontal end if c.maximized_vertical then name = name .. maximized_vertical end - if client.floating.get(c) then name = name .. floating end + if c.floating then name = name .. floating end end end @@ -88,6 +88,7 @@ local function tasklist_label(c, args, tb) else name = name .. (util.escape(c.name) or util.escape("")) end + local focused = capi.client.focus == c -- Handle transient_for: the first parent that does not skip the taskbar -- is considered to be focused, if the real client has skip_taskbar. @@ -98,6 +99,7 @@ local function tasklist_label(c, args, tb) end) == c then focused = true end + if focused then bg = bg_focus text = text .. ""..name..""