| 1 | -- flaw, a Lua OO management framework for Awesome WM widgets. |
| 2 | -- Copyright (C) 2010,2011 David Soulayrol <david.soulayrol AT gmail DOT net> |
| 3 | |
| 4 | -- This program is free software: you can redistribute it and/or modify |
| 5 | -- it under the terms of the GNU General Public License as published by |
| 6 | -- the Free Software Foundation, either version 3 of the License, or |
| 7 | -- (at your option) any later version. |
| 8 | |
| 9 | -- This program is distributed in the hope that it will be useful, |
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | -- GNU General Public License for more details. |
| 13 | |
| 14 | -- You should have received a copy of the GNU General Public License |
| 15 | -- along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | |
| 18 | -- Grab environment. |
| 19 | local capi = { |
| 20 | client = client, |
| 21 | } |
| 22 | |
| 23 | local awful = { |
| 24 | util = require("awful.util"), |
| 25 | } |
| 26 | |
| 27 | local flaw = { |
| 28 | gadget = require('flaw.gadget'), |
| 29 | provider = require('flaw.provider'), |
| 30 | helper = require('flaw.helper'), |
| 31 | } |
| 32 | |
| 33 | --- Clients title display. |
| 34 | -- |
| 35 | -- <p>This module contains a simple text gadget which displays the |
| 36 | -- title of the active client, and its provider. This is a convenient |
| 37 | -- way to see the window title displayed, even if the window bar is |
| 38 | -- not displayed.</p> |
| 39 | -- |
| 40 | -- <h2>Gadget</h2> |
| 41 | -- |
| 42 | -- <p>The title gadget can be instantiated by indexing the gadget |
| 43 | -- module with <code>text.title</code>. The ID parameter has no |
| 44 | -- meaning for the calendar gadget, and it takes no particular |
| 45 | -- parameters. See the <a href="flaw.gadget.html">gadget</a> module |
| 46 | -- documentation to learn about standard gadgets parameters.</p> |
| 47 | -- |
| 48 | -- <div class='example'> |
| 49 | -- g = flaw.gadget.text.title('') |
| 50 | -- </div> |
| 51 | -- |
| 52 | -- <h2>Provider</h2> |
| 53 | -- |
| 54 | -- <p>The provider makes no hardware or software access whatsoever. It |
| 55 | -- simply plugs its <code>update</code> method on the |
| 56 | -- <code>focus</code>, <code>unfocus</code> and |
| 57 | -- <code>property::name</code> signals. This also means the |
| 58 | -- <code>delay</code> parameter has no meaning for it.</p> |
| 59 | -- |
| 60 | -- |
| 61 | -- @author David Soulayrol <david.soulayrol AT gmail DOT com> |
| 62 | -- @copyright 2010,2011 David Soulayrol |
| 63 | module('flaw.title') |
| 64 | |
| 65 | --- The client events provider prototype. |
| 66 | -- |
| 67 | -- <p>The client title provider type is set to |
| 68 | -- <code>title._NAME</code>.</p> |
| 69 | -- |
| 70 | -- @class table |
| 71 | -- @name ClientProvider |
| 72 | ClientProvider = flaw.provider.Provider:new{ type = _NAME } |
| 73 | |
| 74 | --- Display the new client title. |
| 75 | function ClientProvider:update(c) |
| 76 | if c and c.name and capi.client.focus == c then |
| 77 | self.data.title = awful.util.escape(c.name) |
| 78 | self:refresh_gadgets() |
| 79 | end |
| 80 | end |
| 81 | |
| 82 | --- Erase the client title. |
| 83 | function ClientProvider:reset(c) |
| 84 | if c then |
| 85 | self.data.title = '' |
| 86 | self:refresh_gadgets() |
| 87 | end |
| 88 | end |
| 89 | |
| 90 | --- A factory for client providers. |
| 91 | -- |
| 92 | -- @return a brand new client provider. |
| 93 | function provider_factory() |
| 94 | local p = flaw.provider.get(_NAME, '') |
| 95 | -- Create the provider if necessary. |
| 96 | if p == nil then |
| 97 | p = ClientProvider:new{ id = '', data = { title = '' } } |
| 98 | flaw.provider.add(p) |
| 99 | |
| 100 | -- Init signals once for the provider. |
| 101 | capi.client.add_signal( |
| 102 | 'manage', |
| 103 | function (c, startup) |
| 104 | c:add_signal('property::name', |
| 105 | function(c) |
| 106 | p:update(c) |
| 107 | end) |
| 108 | end) |
| 109 | capi.client.add_signal('focus', function(c) p:update(c) end) |
| 110 | capi.client.add_signal('unfocus', function(c) p:reset(c) end) |
| 111 | end |
| 112 | return p |
| 113 | end |
| 114 | |
| 115 | |
| 116 | -- A Text gadget prototype for clients title display. |
| 117 | flaw.gadget.register.text(_M, { pattern = '$title' }) |