2012-10-23 20:32:59 +02:00
|
|
|
---------------------------------------------------------------------------
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Titlebars for awful.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2012-10-23 20:32:59 +02:00
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2012 Uli Schlachter
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @module awful.titlebar
|
2012-10-23 20:32:59 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local error = error
|
|
|
|
local type = type
|
2015-12-05 11:15:20 +01:00
|
|
|
local util = require("awful.util")
|
2012-10-23 20:32:59 +02:00
|
|
|
local abutton = require("awful.button")
|
|
|
|
local aclient = require("awful.client")
|
2015-07-29 21:03:58 +02:00
|
|
|
local atooltip = require("awful.tooltip")
|
2012-10-23 20:32:59 +02:00
|
|
|
local beautiful = require("beautiful")
|
|
|
|
local drawable = require("wibox.drawable")
|
|
|
|
local imagebox = require("wibox.widget.imagebox")
|
|
|
|
local textbox = require("wibox.widget.textbox")
|
2016-02-12 18:19:22 +01:00
|
|
|
local base = require("wibox.widget.base")
|
2012-10-23 20:32:59 +02:00
|
|
|
local capi = {
|
|
|
|
client = client
|
|
|
|
}
|
|
|
|
local titlebar = {
|
|
|
|
widget = {}
|
|
|
|
}
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- The titlebar foreground (text) color.
|
|
|
|
-- @beautiful beautiful.titlebar_fg_normal
|
|
|
|
-- @param color
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- The titlebar background color.
|
|
|
|
-- @beautiful beautiful.titlebar_bg_normal
|
|
|
|
-- @param color
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- The titlebar background image image.
|
|
|
|
-- @beautiful beautiful.titlebar_bgimage_normal
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- The titlebar foreground (text) color.
|
|
|
|
-- @beautiful beautiful.titlebar_fg
|
|
|
|
-- @param color
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- The titlebar background color.
|
|
|
|
-- @beautiful beautiful.titlebar_bg
|
|
|
|
-- @param color
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- The titlebar background image image.
|
|
|
|
-- @beautiful beautiful.titlebar_bgimage
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- The focused titlebar foreground (text) color.
|
|
|
|
-- @beautiful beautiful.titlebar_fg_focus
|
|
|
|
-- @param color
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- The focused titlebar background color.
|
|
|
|
-- @beautiful beautiful.titlebar_bg_focus
|
|
|
|
-- @param color
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- The focused titlebar background image image.
|
|
|
|
-- @beautiful beautiful.titlebar_bgimage_focus
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- floating_button_normal.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_normal
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- maximized_button_normal.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_normal
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- minimize_button_normal.
|
2016-08-14 06:25:31 +02:00
|
|
|
-- @beautiful beautiful.titlebar_minimize_button_normal
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- minimize_button_normal_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_minimize_button_normal_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- minimize_button_normal_press.
|
|
|
|
-- @beautiful beautiful.titlebar_minimize_button_normal_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- close_button_normal.
|
|
|
|
-- @beautiful beautiful.titlebar_close_button_normal
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- close_button_normal_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_close_button_normal_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- close_button_normal_press.
|
|
|
|
-- @beautiful beautiful.titlebar_close_button_normal_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- ontop_button_normal.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_normal
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- sticky_button_normal.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_normal
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- floating_button_focus.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_focus
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- maximized_button_focus.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_focus
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- minimize_button_focus.
|
|
|
|
-- @beautiful beautiful.titlebar_minimize_button_focus
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- minimize_button_focus_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_minimize_button_focus_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- minimize_button_focus_press.
|
|
|
|
-- @beautiful beautiful.titlebar_minimize_button_focus_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- close_button_focus.
|
|
|
|
-- @beautiful beautiful.titlebar_close_button_focus
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- close_button_focus_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_close_button_focus_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- close_button_focus_press.
|
|
|
|
-- @beautiful beautiful.titlebar_close_button_focus_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- ontop_button_focus.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_focus
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- sticky_button_focus.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_focus
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
|
|
|
--- floating_button_normal_active.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_normal_active
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- floating_button_normal_active_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_normal_active_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- floating_button_normal_active_press.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_normal_active_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- maximized_button_normal_active.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_normal_active
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- maximized_button_normal_active_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_normal_active_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- maximized_button_normal_active_press.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_normal_active_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- ontop_button_normal_active.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_normal_active
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- ontop_button_normal_active_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_normal_active_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- ontop_button_normal_active_press.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_normal_active_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- sticky_button_normal_active.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_normal_active
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- sticky_button_normal_active_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_normal_active_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- sticky_button_normal_active_press.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_normal_active_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- floating_button_focus_active.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_focus_active
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- floating_button_focus_active_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_focus_active_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- floating_button_focus_active_press.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_focus_active_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- maximized_button_focus_active.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_focus_active
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- maximized_button_focus_active_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_focus_active_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- maximized_button_focus_active_press.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_focus_active_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- ontop_button_focus_active.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_focus_active
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- ontop_button_focus_active_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_focus_active_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- ontop_button_focus_active_press.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_focus_active_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- sticky_button_focus_active.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_focus_active
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- sticky_button_focus_active_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_focus_active_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- sticky_button_focus_active_press.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_focus_active_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- floating_button_normal_inactive.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_normal_inactive
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- floating_button_normal_inactive_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_normal_inactive_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- floating_button_normal_inactive_press.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_normal_inactive_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- maximized_button_normal_inactive.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_normal_inactive
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- maximized_button_normal_inactive_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_normal_inactive_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- maximized_button_normal_inactive_press.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_normal_inactive_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- ontop_button_normal_inactive.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_normal_inactive
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- ontop_button_normal_inactive_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_normal_inactive_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- ontop_button_normal_inactive_press.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_normal_inactive_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- sticky_button_normal_inactive.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_normal_inactive
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- sticky_button_normal_inactive_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_normal_inactive_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- sticky_button_normal_inactive_press.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_normal_inactive_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- floating_button_focus_inactive.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_focus_inactive
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- floating_button_focus_inactive_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_focus_inactive_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- floating_button_focus_inactive_press.
|
|
|
|
-- @beautiful beautiful.titlebar_floating_button_focus_inactive_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- maximized_button_focus_inactive.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_focus_inactive
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- maximized_button_focus_inactive_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_focus_inactive_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- maximized_button_focus_inactive_press.
|
|
|
|
-- @beautiful beautiful.titlebar_maximized_button_focus_inactive_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- ontop_button_focus_inactive.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_focus_inactive
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- ontop_button_focus_inactive_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_focus_inactive_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- ontop_button_focus_inactive_press.
|
|
|
|
-- @beautiful beautiful.titlebar_ontop_button_focus_inactive_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2016-08-14 06:25:31 +02:00
|
|
|
--- sticky_button_focus_inactive.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_focus_inactive
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-02 22:49:14 +01:00
|
|
|
--- sticky_button_focus_inactive_hover.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_focus_inactive_hover
|
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2017-03-03 00:01:22 +01:00
|
|
|
--- sticky_button_focus_inactive_press.
|
|
|
|
-- @beautiful beautiful.titlebar_sticky_button_focus_inactive_press
|
2017-03-02 22:49:14 +01:00
|
|
|
-- @param surface
|
|
|
|
-- @see gears.surface
|
|
|
|
|
2015-09-27 17:00:01 +02:00
|
|
|
--- 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
|
|
|
|
-- @name setup
|
|
|
|
-- @class function
|
|
|
|
|
2016-01-06 13:20:04 +01:00
|
|
|
--- Show tooltips when hover on titlebar buttons (defaults to 'true')
|
|
|
|
titlebar.enable_tooltip = true
|
|
|
|
|
2012-10-23 20:32:59 +02:00
|
|
|
local all_titlebars = setmetatable({}, { __mode = 'k' })
|
|
|
|
|
|
|
|
-- Get a color for a titlebar, this tests many values from the array and the theme
|
|
|
|
local function get_color(name, c, args)
|
|
|
|
local suffix = "_normal"
|
|
|
|
if capi.client.focus == c then
|
|
|
|
suffix = "_focus"
|
|
|
|
end
|
|
|
|
local function get(array)
|
|
|
|
return array["titlebar_"..name..suffix] or array["titlebar_"..name] or array[name..suffix] or array[name]
|
|
|
|
end
|
|
|
|
return get(args) or get(beautiful)
|
|
|
|
end
|
|
|
|
|
2013-09-19 14:37:07 +02:00
|
|
|
local function get_titlebar_function(c, position)
|
|
|
|
if position == "left" then
|
|
|
|
return c.titlebar_left
|
|
|
|
elseif position == "right" then
|
|
|
|
return c.titlebar_right
|
|
|
|
elseif position == "top" then
|
|
|
|
return c.titlebar_top
|
|
|
|
elseif position == "bottom" then
|
|
|
|
return c.titlebar_bottom
|
|
|
|
else
|
|
|
|
error("Invalid titlebar position '" .. position .. "'")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-23 20:32:59 +02:00
|
|
|
--- Get a client's titlebar
|
|
|
|
-- @class function
|
2016-08-01 21:35:00 +02:00
|
|
|
-- @tparam client c The client for which a titlebar is wanted.
|
2016-11-21 22:38:23 +01:00
|
|
|
-- @tparam[opt={}] table args A table with extra arguments for the titlebar.
|
|
|
|
-- @tparam[opt=font.height*1.5] number args.size The height of the titlebar.
|
2016-08-01 21:35:00 +02:00
|
|
|
-- @tparam[opt=top] string args.position" values are `top`,
|
|
|
|
-- `left`, `right` and `bottom`.
|
|
|
|
-- @tparam[opt=top] string args.bg_normal
|
|
|
|
-- @tparam[opt=top] string args.bg_focus
|
|
|
|
-- @tparam[opt=top] string args.bgimage_normal
|
|
|
|
-- @tparam[opt=top] string args.bgimage_focus
|
|
|
|
-- @tparam[opt=top] string args.fg_normal
|
|
|
|
-- @tparam[opt=top] string args.fg_focus
|
|
|
|
-- @tparam[opt=top] string args.font
|
2012-10-23 20:32:59 +02:00
|
|
|
-- @name titlebar
|
|
|
|
local function new(c, args)
|
2016-02-07 15:02:25 +01:00
|
|
|
args = args or {}
|
2012-10-23 20:32:59 +02:00
|
|
|
local position = args.position or "top"
|
2015-12-05 11:15:20 +01:00
|
|
|
local size = args.size or util.round(beautiful.get_font_height(args.font) * 1.5)
|
2013-09-19 14:37:07 +02:00
|
|
|
local d = get_titlebar_function(c, position)(c, size)
|
2012-10-23 20:32:59 +02:00
|
|
|
|
|
|
|
-- Make sure that there is never more than one titlebar for any given client
|
|
|
|
local bars = all_titlebars[c]
|
|
|
|
if not bars then
|
|
|
|
bars = {}
|
|
|
|
all_titlebars[c] = bars
|
|
|
|
end
|
|
|
|
|
|
|
|
local ret
|
|
|
|
if not bars[position] then
|
2015-08-08 13:13:47 +02:00
|
|
|
local context = {
|
|
|
|
client = c,
|
|
|
|
position = position
|
|
|
|
}
|
|
|
|
ret = drawable(d, context, "awful.titlebar")
|
2016-10-04 21:18:18 +02:00
|
|
|
ret:_inform_visible(true)
|
2012-11-29 16:52:19 +01:00
|
|
|
local function update_colors()
|
2016-02-07 15:02:25 +01:00
|
|
|
local args_ = bars[position].args
|
|
|
|
ret:set_bg(get_color("bg", c, args_))
|
|
|
|
ret:set_fg(get_color("fg", c, args_))
|
|
|
|
ret:set_bgimage(get_color("bgimage", c, args_))
|
2012-11-29 16:52:19 +01:00
|
|
|
end
|
2012-10-23 20:32:59 +02:00
|
|
|
|
|
|
|
bars[position] = {
|
|
|
|
args = args,
|
2012-11-29 16:52:19 +01:00
|
|
|
drawable = ret,
|
|
|
|
update_colors = update_colors
|
2012-10-23 20:32:59 +02:00
|
|
|
}
|
2012-11-29 16:52:19 +01:00
|
|
|
|
|
|
|
-- Update the colors when focus changes
|
|
|
|
c:connect_signal("focus", update_colors)
|
|
|
|
c:connect_signal("unfocus", update_colors)
|
2016-10-04 21:18:18 +02:00
|
|
|
|
|
|
|
-- Inform the drawable when it becomes invisible
|
|
|
|
c:connect_signal("unmanage", function() ret:_inform_visible(false) end)
|
2012-10-23 20:32:59 +02:00
|
|
|
else
|
|
|
|
bars[position].args = args
|
|
|
|
ret = bars[position].drawable
|
|
|
|
end
|
|
|
|
|
2012-11-29 16:52:19 +01:00
|
|
|
-- Make sure the titlebar has the right colors applied
|
|
|
|
bars[position].update_colors()
|
2012-10-23 20:32:59 +02:00
|
|
|
|
2015-09-27 17:00:01 +02:00
|
|
|
-- Handle declarative/recursive widget container
|
|
|
|
ret.setup = base.widget.setup
|
|
|
|
|
2012-10-23 20:32:59 +02:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2013-09-19 14:37:07 +02:00
|
|
|
--- Show a client's titlebar.
|
|
|
|
-- @param c The client whose titlebar is modified
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @param[opt] position The position of the titlebar. Must be one of "left",
|
2015-10-14 00:21:29 +02:00
|
|
|
-- "right", "top", "bottom". Default is "top".
|
2013-09-19 14:37:07 +02:00
|
|
|
function titlebar.show(c, position)
|
2016-02-07 15:02:25 +01:00
|
|
|
position = position or "top"
|
2013-09-19 14:37:07 +02:00
|
|
|
local bars = all_titlebars[c]
|
|
|
|
local data = bars and bars[position]
|
|
|
|
local args = data and data.args
|
|
|
|
new(c, args)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Hide a client's titlebar.
|
|
|
|
-- @param c The client whose titlebar is modified
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @param[opt] position The position of the titlebar. Must be one of "left",
|
2015-10-14 00:21:29 +02:00
|
|
|
-- "right", "top", "bottom". Default is "top".
|
2013-09-19 14:37:07 +02:00
|
|
|
function titlebar.hide(c, position)
|
2016-02-07 15:02:25 +01:00
|
|
|
position = position or "top"
|
2013-09-19 14:37:07 +02:00
|
|
|
get_titlebar_function(c, position)(c, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Toggle a client's titlebar, hiding it if it is visible, otherwise showing it.
|
|
|
|
-- @param c The client whose titlebar is modified
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @param[opt] position The position of the titlebar. Must be one of "left",
|
2015-10-14 00:21:29 +02:00
|
|
|
-- "right", "top", "bottom". Default is "top".
|
2013-09-19 14:37:07 +02:00
|
|
|
function titlebar.toggle(c, position)
|
2016-02-07 15:02:25 +01:00
|
|
|
position = position or "top"
|
|
|
|
local _, size = get_titlebar_function(c, position)(c)
|
2013-09-19 14:37:07 +02:00
|
|
|
if size == 0 then
|
|
|
|
titlebar.show(c, position)
|
|
|
|
else
|
|
|
|
titlebar.hide(c, position)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-23 20:32:59 +02:00
|
|
|
--- Create a new titlewidget. A title widget displays the name of a client.
|
|
|
|
-- Please note that this returns a textbox and all of textbox' API is available.
|
|
|
|
-- This way, you can e.g. modify the font that is used.
|
|
|
|
-- @param c The client for which a titlewidget should be created.
|
|
|
|
-- @return The title widget.
|
|
|
|
function titlebar.widget.titlewidget(c)
|
|
|
|
local ret = textbox()
|
|
|
|
local function update()
|
|
|
|
ret:set_text(c.name or "<unknown>")
|
|
|
|
end
|
|
|
|
c:connect_signal("property::name", update)
|
|
|
|
update()
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new icon widget. An icon widget displays the icon of a client.
|
|
|
|
-- Please note that this returns an imagebox and all of the imagebox' API is
|
|
|
|
-- available. This way, you can e.g. disallow resizes.
|
|
|
|
-- @param c The client for which an icon widget should be created.
|
|
|
|
-- @return The icon widget.
|
|
|
|
function titlebar.widget.iconwidget(c)
|
|
|
|
local ret = imagebox()
|
|
|
|
local function update()
|
|
|
|
ret:set_image(c.icon)
|
|
|
|
end
|
|
|
|
c:connect_signal("property::icon", update)
|
|
|
|
update()
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new button widget. A button widget displays an image and reacts to
|
|
|
|
-- mouse clicks. Please note that the caller has to make sure that this widget
|
|
|
|
-- gets redrawn when needed by calling the returned widget's update() function.
|
|
|
|
-- The selector function should return a value describing a state. If the value
|
|
|
|
-- is a boolean, either "active" or "inactive" are used. The actual image is
|
|
|
|
-- then found in the theme as "titlebar_[name]_button_[normal/focus]_[state]".
|
|
|
|
-- If that value does not exist, the focused state is ignored for the next try.
|
|
|
|
-- @param c The client for which a button is created.
|
2015-07-29 21:03:58 +02:00
|
|
|
-- @tparam string name Name of the button, used for accessing the theme and
|
|
|
|
-- in the tooltip.
|
2012-10-23 20:32:59 +02:00
|
|
|
-- @param selector A function that selects the image that should be displayed.
|
|
|
|
-- @param action Function that is called when the button is clicked.
|
|
|
|
-- @return The widget
|
|
|
|
function titlebar.widget.button(c, name, selector, action)
|
|
|
|
local ret = imagebox()
|
2015-07-29 21:03:58 +02:00
|
|
|
|
2016-01-06 13:20:04 +01:00
|
|
|
if titlebar.enable_tooltip then
|
2016-05-31 05:09:50 +02:00
|
|
|
ret._private.tooltip = atooltip({ objects = {ret}, delay_show = 1 })
|
|
|
|
ret._private.tooltip:set_text(name)
|
2016-01-06 13:20:04 +01:00
|
|
|
end
|
2015-07-29 21:03:58 +02:00
|
|
|
|
2012-10-23 20:32:59 +02:00
|
|
|
local function update()
|
|
|
|
local img = selector(c)
|
|
|
|
if type(img) ~= "nil" then
|
|
|
|
-- Convert booleans automatically
|
|
|
|
if type(img) == "boolean" then
|
|
|
|
if img then
|
|
|
|
img = "active"
|
|
|
|
else
|
|
|
|
img = "inactive"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local prefix = "normal"
|
|
|
|
if capi.client.focus == c then
|
|
|
|
prefix = "focus"
|
|
|
|
end
|
|
|
|
if img ~= "" then
|
|
|
|
prefix = prefix .. "_"
|
|
|
|
end
|
2017-03-02 22:49:14 +01:00
|
|
|
if ret.state ~= "" then
|
|
|
|
img = img .. "_"
|
|
|
|
end
|
2016-09-15 16:21:49 +02:00
|
|
|
-- First try with a prefix based on the client's focus state,
|
|
|
|
-- then try again without that prefix if nothing was found,
|
|
|
|
-- and finally, try a fallback for compatibility with Awesome 3.5 themes
|
2017-03-02 22:49:14 +01:00
|
|
|
local theme = beautiful["titlebar_" .. name .. "_button_" .. prefix .. img .. ret.state]
|
|
|
|
or beautiful["titlebar_" .. name .. "_button_" .. prefix .. img]
|
2016-09-15 16:21:49 +02:00
|
|
|
or beautiful["titlebar_" .. name .. "_button_" .. img]
|
|
|
|
or beautiful["titlebar_" .. name .. "_button_" .. prefix .. "_inactive"]
|
2012-10-23 20:32:59 +02:00
|
|
|
if theme then
|
|
|
|
img = theme
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ret:set_image(img)
|
|
|
|
end
|
2017-03-02 22:49:14 +01:00
|
|
|
ret.state = ""
|
2012-10-23 20:32:59 +02:00
|
|
|
if action then
|
2017-03-02 22:49:14 +01:00
|
|
|
ret:buttons(abutton({ }, 1, nil, function()
|
|
|
|
ret.state = ""
|
|
|
|
update()
|
|
|
|
action(c, selector(c))
|
|
|
|
end))
|
|
|
|
else
|
2017-03-03 00:01:22 +01:00
|
|
|
ret:buttons(abutton({ }, 1, nil, function()
|
|
|
|
ret.state = ""
|
|
|
|
update()
|
|
|
|
end))
|
2012-10-23 20:32:59 +02:00
|
|
|
end
|
2017-03-02 22:49:14 +01:00
|
|
|
ret:connect_signal("mouse::enter", function()
|
|
|
|
ret.state = "hover"
|
|
|
|
update()
|
|
|
|
end)
|
|
|
|
ret:connect_signal("mouse::leave", function()
|
|
|
|
ret.state = ""
|
|
|
|
update()
|
|
|
|
end)
|
2017-03-03 00:01:22 +01:00
|
|
|
ret:connect_signal("button::press", function(_, _, _, b)
|
2017-03-02 22:49:14 +01:00
|
|
|
if b == 1 then
|
2017-03-03 00:01:22 +01:00
|
|
|
ret.state = "press"
|
2017-03-02 22:49:14 +01:00
|
|
|
update()
|
|
|
|
end
|
|
|
|
end)
|
2012-10-23 20:32:59 +02:00
|
|
|
ret.update = update
|
|
|
|
update()
|
|
|
|
|
|
|
|
-- We do magic based on whether a client is focused above, so we need to
|
|
|
|
-- connect to the corresponding signal here.
|
2016-01-24 13:45:06 +01:00
|
|
|
c:connect_signal("focus", update)
|
|
|
|
c:connect_signal("unfocus", update)
|
2012-10-23 20:32:59 +02:00
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new float button for a client.
|
|
|
|
-- @param c The client for which the button is wanted.
|
|
|
|
function titlebar.widget.floatingbutton(c)
|
2016-03-14 07:21:29 +01:00
|
|
|
local widget = titlebar.widget.button(c, "floating", aclient.object.get_floating, aclient.floating.toggle)
|
2012-10-23 20:32:59 +02:00
|
|
|
c:connect_signal("property::floating", widget.update)
|
|
|
|
return widget
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new maximize button for a client.
|
|
|
|
-- @param c The client for which the button is wanted.
|
|
|
|
function titlebar.widget.maximizedbutton(c)
|
2016-02-07 15:02:25 +01:00
|
|
|
local widget = titlebar.widget.button(c, "maximized", function(cl)
|
2017-01-24 10:19:45 +01:00
|
|
|
return cl.maximized
|
2016-02-07 15:02:25 +01:00
|
|
|
end, function(cl, state)
|
2017-01-24 10:19:45 +01:00
|
|
|
cl.maximized = not state
|
2012-10-23 20:32:59 +02:00
|
|
|
end)
|
2017-01-24 10:19:45 +01:00
|
|
|
c:connect_signal("property::maximized", widget.update)
|
2012-10-23 20:32:59 +02:00
|
|
|
return widget
|
|
|
|
end
|
|
|
|
|
2013-11-03 00:02:09 +01:00
|
|
|
--- Create a new minimize button for a client.
|
|
|
|
-- @param c The client for which the button is wanted.
|
|
|
|
function titlebar.widget.minimizebutton(c)
|
2017-03-03 23:11:06 +01:00
|
|
|
local widget = titlebar.widget.button(c, "minimize",
|
|
|
|
function() return "" end,
|
|
|
|
function(cl) cl.minimized = not cl.minimized end)
|
2013-11-03 00:02:09 +01:00
|
|
|
c:connect_signal("property::minimized", widget.update)
|
|
|
|
return widget
|
|
|
|
end
|
|
|
|
|
2012-10-23 20:32:59 +02:00
|
|
|
--- Create a new closing button for a client.
|
|
|
|
-- @param c The client for which the button is wanted.
|
|
|
|
function titlebar.widget.closebutton(c)
|
2016-02-07 15:02:25 +01:00
|
|
|
return titlebar.widget.button(c, "close", function() return "" end, function(cl) cl:kill() end)
|
2012-10-23 20:32:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new ontop button for a client.
|
|
|
|
-- @param c The client for which the button is wanted.
|
|
|
|
function titlebar.widget.ontopbutton(c)
|
2017-03-03 23:11:06 +01:00
|
|
|
local widget = titlebar.widget.button(c, "ontop",
|
|
|
|
function(cl) return cl.ontop end,
|
|
|
|
function(cl, state) cl.ontop = not state end)
|
2012-10-23 20:32:59 +02:00
|
|
|
c:connect_signal("property::ontop", widget.update)
|
|
|
|
return widget
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new sticky button for a client.
|
|
|
|
-- @param c The client for which the button is wanted.
|
|
|
|
function titlebar.widget.stickybutton(c)
|
2017-03-03 23:11:06 +01:00
|
|
|
local widget = titlebar.widget.button(c, "sticky",
|
|
|
|
function(cl) return cl.sticky end,
|
|
|
|
function(cl, state) cl.sticky = not state end)
|
2012-10-23 20:32:59 +02:00
|
|
|
c:connect_signal("property::sticky", widget.update)
|
|
|
|
return widget
|
|
|
|
end
|
|
|
|
|
2016-01-24 16:27:31 +01:00
|
|
|
client.connect_signal("unmanage", function(c)
|
|
|
|
all_titlebars[c] = nil
|
|
|
|
end)
|
|
|
|
|
2012-10-23 20:32:59 +02:00
|
|
|
return setmetatable(titlebar, { __call = function(_, ...) return new(...) end})
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|