Merge pull request #873 from Elv13/geometry_overhaul_p3.01

Geometry overhaul p3.01
This commit is contained in:
Emmanuel Lepage Vallée 2016-05-05 16:23:11 -04:00
commit 504018343b
7 changed files with 285 additions and 17 deletions

View File

@ -85,6 +85,9 @@ file = {
-- Ignore some parts of the widget library
'../lib/awful/widget/init.lua',
-- Ignore the drawing window, users should only care about wiboxes
'../objects/drawin.c',
-- exclude layout, but we need an extra bit of documentation elsewhere.
'../lib/awful/layout/suit/'
}

View File

@ -297,13 +297,59 @@ function mouse.object.set_current_client() end
function mouse.object.get_current_wibox()
local obj = capi.mouse.object_under_pointer()
if type(obj) == "drawin" then
return obj
if type(obj) == "drawin" and obj.get_wibox then
return obj:get_wibox()
end
end
function mouse.object.set_current_wibox() end
--- Get the widgets currently under the mouse cursor.
--
-- @property current_widgets
-- @tparam nil|table list The widget list
-- @treturn table The list of widgets.The first element is the biggest
-- container while the last is the topmost widget. The table contains *x*, *y*,
-- *width*, *height* and *widget*.
-- @treturn table The list of geometries.
-- @see wibox.find_widgets
function mouse.object.get_current_widgets()
local w = mouse.object.get_current_wibox()
if w then
local geo, coords = w:geometry(), capi.mouse:coords()
local list = w:find_widgets(coords.x - geo.x, coords.y - geo.y)
local ret = {}
for k, v in ipairs(list) do
ret[k] = v.widget
end
return ret, list
end
end
function mouse.object.set_current_widgets() end
--- Get the topmost widget currently under the mouse cursor.
-- @property current_widget
-- @tparam widget|nil widget The widget
-- @treturn ?widget The widget
-- @treturn ?table The geometry.
-- @see wibox.find_widgets
function mouse.object.get_current_widget()
local wdgs, geos = mouse.object.get_current_widgets()
if wdgs then
return wdgs[#wdgs], geos[#geos]
end
end
function mouse.object.set_current_widget() end
--- True if the left mouse button is pressed.
-- @property is_left_mouse_button_pressed
-- @param boolean

View File

@ -20,7 +20,7 @@ local base = require("wibox.widget.base")
--- This provides widget box windows. Every wibox can also be used as if it were
-- a drawin. All drawin functions and properties are also available on wiboxes!
-- wibox
local wibox = { mt = {} }
local wibox = { mt = {}, object = {} }
wibox.layout = require("wibox.layout")
wibox.widget = require("wibox.widget")
wibox.drawable = require("wibox.drawable")
@ -31,6 +31,189 @@ function wibox:set_widget(widget)
self._drawable:set_widget(widget)
end
-- Import some drawin documentation
--- Border width.
--
-- **Signal:**
--
-- * *property::border_width*
--
-- @property border_width
-- @param integer
--- Border color.
--
-- Please note that this property only support string based 24 bit or 32 bit
-- colors:
--
-- Red Blue
-- _| _|
-- #FF00FF
-- T‾
-- Green
--
--
-- Red Blue
-- _| _|
-- #FF00FF00
-- T‾ ‾T
-- Green Alpha
--
-- **Signal:**
--
-- * *property::border_color*
--
-- @property border_color
-- @param string
--- On top of other windows.
--
-- **Signal:**
--
-- * *property::ontop*
--
-- @property ontop
-- @param boolean
--- The mouse cursor.
--
-- **Signal:**
--
-- * *property::cursor*
--
-- @property cursor
-- @param string
-- @see mouse
--- Visibility.
--
-- **Signal:**
--
-- * *property::visible*
--
-- @property visible
-- @param boolean
--- The opacity of the wibox, between 0 and 1.
--
-- **Signal:**
--
-- * *property::opacity*
--
-- @property opacity
-- @tparam number opacity (between 0 and 1)
--- The window type (desktop, normal, dock, ...).
--
-- **Signal:**
--
-- * *property::type*
--
-- @property type
-- @param string
-- @see client.type
--- The x coordinates.
--
-- **Signal:**
--
-- * *property::x*
--
-- @property x
-- @param integer
--- The y coordinates.
--
-- **Signal:**
--
-- * *property::y*
--
-- @property y
-- @param integer
--- The width of the wibox.
--
-- **Signal:**
--
-- * *property::width*
--
-- @property width
-- @param width
--- The height of the wibox.
--
-- **Signal:**
--
-- * *property::height*
--
-- @property height
-- @param height
--- The wibox's `drawable`.
--
-- **Signal:**
--
-- * *property::drawable*
--
-- @property drawable
-- @tparam drawable drawable
--- The X window id.
--
-- **Signal:**
--
-- * *property::window*
--
-- @property window
-- @param string
-- @see client.window
--- The wibox's bounding shape as a (native) cairo surface.
--
-- **Signal:**
--
-- * *property::shape_bounding*
--
-- @property shape_bounding
-- @param surface._native
--- The wibox's clip shape as a (native) cairo surface.
--
-- **Signal:**
--
-- * *property::shape_clip*
--
-- @property shape_clip
-- @param surface._native
--- Get or set mouse buttons bindings to a wibox.
--
-- @param buttons_table A table of buttons objects, or nothing.
-- @function wibox.buttons
--- Get or set wibox geometry. That's the same as accessing or setting the x,
-- y, width or height properties of a wibox.
--
-- @param A table with coordinates to modify.
-- @return A table with wibox coordinates and geometry.
-- @function wibox.geometry
--- Get or set wibox struts.
--
-- @param strut A table with new strut, or nothing
-- @return The wibox strut in a table.
-- @function wibox.struts
-- @see client.struts
--- The default background color.
-- @beautiful beautiful.bg_normal
-- @see set_bg
--- The default foreground (text) color.
-- @beautiful beautiful.fg_normal
-- @see set_fg
--- Set a declarative widget hierarchy description.
-- See [The declarative layout system](../documentation/03-declarative-layout.md.html)
-- @param args An array containing the widgets disposition
@ -62,10 +245,11 @@ end
--- Find a widget by a point.
-- The wibox must have drawn itself at least once for this to work.
-- @param x X coordinate of the point
-- @param y Y coordinate of the point
-- @return A sorted table with all widgets that contain the given point. The
-- widgets are sorted by relevance.
-- @tparam number x X coordinate of the point
-- @tparam number y Y coordinate of the point
-- @treturn table A sorted table of widgets positions. The first element is the biggest
-- container while the last is the topmost widget. The table contains *x*, *y*,
-- *width*, *height* and *widget*.
function wibox:find_widgets(x, y)
return self._drawable:find_widgets(x, y)
end
@ -115,6 +299,14 @@ end
local function new(args)
local ret = object()
local w = capi.drawin(args)
-- lua 5.1 and luajit have issues with self referencing loops
local avoid_leak = setmetatable({ret},{__mode="v"})
function w.get_wibox()
return avoid_leak[1]
end
ret.drawin = w
ret._drawable = wibox.drawable(w.drawable, { wibox = ret },
"wibox drawable (" .. object.modulename(3) .. ")")
@ -156,22 +348,24 @@ local function new(args)
return ret
end
capi.drawin.add_signal("property::get_wibox")
--- Redraw a wibox. You should never have to call this explicitely because it is
-- automatically called when needed.
-- @param wibox
-- @function draw
--- Widget box object.
-- Every wibox "inherits" from a drawin and you can use all of drawin's
-- functions directly on this as well. When creating a wibox, you can specify a
-- "fg" and a "bg" color as keys in the table that is passed to the constructor.
-- All other arguments will be passed to drawin's constructor.
-- @table drawin
function wibox.mt:__call(...)
return new(...)
end
-- Extend the luaobject
object.properties(capi.drawin, {
getter_class = wibox.object,
setter_class = wibox.object,
auto_emit = true,
})
return setmetatable(wibox, wibox.mt)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -128,7 +128,7 @@
*
* @property workarea
* @see client.struts
* @see drawin.struts
* @see wibox.struts
* @param table
* @tfield integer table.x The horizontal position
* @tfield integer table.y The vertical position

View File

@ -5,13 +5,14 @@ local pango = require("lgi").Pango
local pangocairo = require("lgi").PangoCairo
-- Set the global shims
-- luacheck: globals awesome root tag screen client mouse
-- luacheck: globals awesome root tag screen client mouse drawin
awesome = require( "awesome" )
root = require( "root" )
tag = require( "tag" )
screen = require( "screen" )
client = require( "client" )
mouse = require( "mouse" )
drawin = require( "drawin" )
-- Force luacheck to be silent about setting those as unused globals
assert(awesome and root and tag and screen and client and mouse)

View File

@ -0,0 +1,23 @@
local gears_obj = require("gears.object")
local drawin, meta = awesome._shim_fake_class()
local function new_drawin(_, args)
local ret = gears_obj()
for k, v in pairs(args) do
rawset(ret, k, v)
end
return setmetatable(ret, {
__index = function(...) return meta.__index(...) end,
__newindex = function(...) return meta.__newindex(...) end
})
end
return setmetatable(drawin, {
__call = new_drawin,
})
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -1,10 +1,11 @@
local file_path, image_path, luacovpath = ...
-- Set the global shims
-- luacheck: globals awesome client tag
-- luacheck: globals awesome client tag drawin
awesome = require( "awesome" )
client = require( "client" )
tag = require( "tag" )
drawin = require( "drawin" )
-- Force luacheck to be silent about setting those as unused globals
assert(awesome and client and tag)