2008-06-09 21:43:09 +02:00
|
|
|
/*
|
|
|
|
* tag.c - tag management
|
|
|
|
*
|
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-10-03 07:01:14 +02:00
|
|
|
/** awesome tag API.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2019-09-30 05:50:25 +02:00
|
|
|
* What is a tag?
|
|
|
|
* ==============
|
|
|
|
*
|
|
|
|
* In AwesomeWM, a `tag` is a group of clients. It can either be used as labels
|
|
|
|
* or as more classical workspaces depending on how they are configured.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2016-04-07 05:13:13 +02:00
|
|
|
* ![Client geometry](../images/tag_props.svg)
|
|
|
|
*
|
2019-09-30 05:50:25 +02:00
|
|
|
* * A **tag** can be attached to **multiple clients**
|
|
|
|
* * A **client** can be attached to **multiple tags**
|
|
|
|
* * A **tag** can only be in 1 screen *any given time*, but can be moved
|
|
|
|
* * All **clients** attached to a tag **must be in the same screen as the tag**
|
|
|
|
*
|
|
|
|
* Creating tags
|
|
|
|
* =============
|
2016-12-20 02:39:40 +01:00
|
|
|
*
|
|
|
|
* The default config initializes tags like this:
|
|
|
|
*
|
|
|
|
* awful.tag(
|
|
|
|
* { "1", "2", "3", "4", "5", "6", "7", "8", "9" },
|
|
|
|
* s,
|
|
|
|
* awful.layout.layouts[1]
|
|
|
|
* )
|
|
|
|
*
|
|
|
|
* If you wish to have tags with different properties, then `awful.tag.add` is
|
|
|
|
* a better choice:
|
|
|
|
*
|
|
|
|
* awful.tag.add("First tag", {
|
|
|
|
* icon = "/path/to/icon1.png",
|
|
|
|
* layout = awful.layout.suit.tile,
|
|
|
|
* master_fill_policy = "master_width_factor",
|
|
|
|
* gap_single_client = true,
|
|
|
|
* gap = 15,
|
|
|
|
* screen = s,
|
2017-02-04 15:13:12 +01:00
|
|
|
* selected = true,
|
2017-01-04 06:12:44 +01:00
|
|
|
* })
|
2016-12-20 02:39:40 +01:00
|
|
|
*
|
|
|
|
* awful.tag.add("Second tag", {
|
|
|
|
* icon = "/path/to/icon2.png",
|
|
|
|
* layout = awful.layout.suit.max,
|
|
|
|
* screen = s,
|
2017-01-04 06:12:44 +01:00
|
|
|
* })
|
2016-12-20 02:39:40 +01:00
|
|
|
*
|
2017-02-04 15:13:12 +01:00
|
|
|
* Note: the example above sets "First tag" to be selected explicitly,
|
|
|
|
* because otherwise you will find yourself without any selected tag.
|
|
|
|
*
|
2019-09-30 05:50:25 +02:00
|
|
|
* Accessing tags
|
|
|
|
* ==============
|
2016-12-20 02:40:14 +01:00
|
|
|
*
|
|
|
|
* To access the "current tags", use
|
|
|
|
*
|
|
|
|
* local tags = awful.screen.focused().selected_tags
|
|
|
|
*
|
|
|
|
* See: `awful.screen.focused`
|
|
|
|
*
|
|
|
|
* See: `screen.selected_tags`
|
|
|
|
*
|
|
|
|
* To ignore the corner case where multiple tags are selected:
|
|
|
|
*
|
|
|
|
* local t = awful.screen.focused().selected_tag
|
|
|
|
*
|
|
|
|
* See: `screen.selected_tag`
|
|
|
|
*
|
|
|
|
* To get all tags for the focused screen:
|
|
|
|
*
|
|
|
|
* local tags = awful.screen.focused().tags
|
|
|
|
*
|
|
|
|
* See: `screen.tags`
|
|
|
|
*
|
|
|
|
* To get all tags:
|
|
|
|
*
|
|
|
|
* local tags = root.tags()
|
|
|
|
*
|
|
|
|
* To get the current tag of the focused client:
|
|
|
|
*
|
|
|
|
* local t = client.focus and client.focus.first_tag or nil
|
|
|
|
*
|
|
|
|
* See: `client.focus`
|
|
|
|
* See: `client.first_tag`
|
|
|
|
*
|
|
|
|
* To get a tag from its name:
|
|
|
|
*
|
|
|
|
* local t = awful.tag.find_by_name(awful.screen.focused(), "name")
|
|
|
|
*
|
2019-09-30 05:50:25 +02:00
|
|
|
* Common keybindings code
|
|
|
|
* =======================
|
2016-12-20 02:40:34 +01:00
|
|
|
*
|
|
|
|
* Here is a few useful shortcuts not part of the default `rc.lua`. Add these
|
|
|
|
* functions above `-- {{{ Key bindings`:
|
|
|
|
*
|
|
|
|
* Delete the current tag
|
|
|
|
*
|
|
|
|
* local function delete_tag()
|
|
|
|
* local t = awful.screen.focused().selected_tag
|
|
|
|
* if not t then return end
|
|
|
|
* t:delete()
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Create a new tag at the end of the list
|
|
|
|
*
|
|
|
|
* local function add_tag()
|
2017-08-07 20:35:39 +02:00
|
|
|
* awful.tag.add("NewTag", {
|
|
|
|
* screen = awful.screen.focused(),
|
|
|
|
* layout = awful.layout.suit.floating }):view_only()
|
2016-12-20 02:40:34 +01:00
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Rename the current tag
|
|
|
|
*
|
|
|
|
* local function rename_tag()
|
|
|
|
* awful.prompt.run {
|
|
|
|
* prompt = "New tag name: ",
|
|
|
|
* textbox = awful.screen.focused().mypromptbox.widget,
|
|
|
|
* exe_callback = function(new_name)
|
|
|
|
* if not new_name or #new_name == 0 then return end
|
|
|
|
*
|
|
|
|
* local t = awful.screen.focused().selected_tag
|
|
|
|
* if t then
|
|
|
|
* t.name = new_name
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* }
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Move the focused client to a new tag
|
|
|
|
*
|
|
|
|
* local function move_to_new_tag()
|
|
|
|
* local c = client.focus
|
|
|
|
* if not c then return end
|
|
|
|
*
|
|
|
|
* local t = awful.tag.add(c.class,{screen= c.screen })
|
|
|
|
* c:tags({t})
|
|
|
|
* t:view_only()
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Copy the current tag at the end of the list
|
|
|
|
*
|
|
|
|
* local function copy_tag()
|
|
|
|
* local t = awful.screen.focused().selected_tag
|
|
|
|
* if not t then return end
|
|
|
|
*
|
|
|
|
* local clients = t:clients()
|
|
|
|
* local t2 = awful.tag.add(t.name, awful.tag.getdata(t))
|
|
|
|
* t2:clients(clients)
|
|
|
|
* t2:view_only()
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* And, in the `globalkeys` table:
|
|
|
|
*
|
|
|
|
* awful.key({ modkey, }, "a", add_tag,
|
|
|
|
* {description = "add a tag", group = "tag"}),
|
|
|
|
* awful.key({ modkey, "Shift" }, "a", delete_tag,
|
|
|
|
* {description = "delete the current tag", group = "tag"}),
|
|
|
|
* awful.key({ modkey, "Control" }, "a", move_to_new_tag,
|
|
|
|
* {description = "add a tag with the focused client", group = "tag"}),
|
|
|
|
* awful.key({ modkey, "Mod1" }, "a", copy_tag,
|
|
|
|
* {description = "create a copy of the current tag", group = "tag"}),
|
|
|
|
* awful.key({ modkey, "Shift" }, "r", rename_tag,
|
|
|
|
* {description = "rename the current tag", group = "tag"}),
|
|
|
|
*
|
|
|
|
* See the
|
|
|
|
* <a href="../documentation/05-awesomerc.md.html#global_keybindings">
|
|
|
|
* global keybindings
|
|
|
|
* </a> for more information about the keybindings.
|
|
|
|
*
|
2015-02-27 00:24:23 +01:00
|
|
|
* Some signal names are starting with a dot. These dots are artefacts from
|
|
|
|
* the documentation generation, you get the real signal name by
|
|
|
|
* removing the starting dot.
|
|
|
|
*
|
2019-06-27 08:14:17 +02:00
|
|
|
* @DOC_uml_nav_tables_tag_EXAMPLE@
|
|
|
|
*
|
2015-02-27 00:24:23 +01:00
|
|
|
* @author Julien Danjou <julien@danjou.info>
|
|
|
|
* @copyright 2008-2009 Julien Danjou
|
2019-06-06 08:40:00 +02:00
|
|
|
* @coreclassmod tag
|
2015-02-27 00:24:23 +01:00
|
|
|
*/
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
#include "tag.h"
|
2016-12-31 15:29:28 +01:00
|
|
|
#include "screen.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "banning.h"
|
2008-06-09 21:43:09 +02:00
|
|
|
#include "client.h"
|
|
|
|
#include "ewmh.h"
|
2009-08-17 16:38:56 +02:00
|
|
|
#include "luaa.h"
|
2008-06-09 21:43:09 +02:00
|
|
|
|
2020-04-17 19:25:40 +02:00
|
|
|
lua_class_t tag_class;
|
|
|
|
|
2019-12-01 05:57:47 +01:00
|
|
|
/** When a tag requests to be selected.
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal request::select
|
2019-12-01 05:57:47 +01:00
|
|
|
* @tparam string context The reason why it was called.
|
2019-12-01 07:53:12 +01:00
|
|
|
* @request tag select ewmh granted When the client request to be moved to a
|
|
|
|
* specific virtual desktop. AwesomeWM interprets virtual desktop as indexed
|
|
|
|
* tags.
|
2016-06-04 17:39:14 +02:00
|
|
|
*/
|
|
|
|
|
2019-11-11 07:55:54 +01:00
|
|
|
/**
|
|
|
|
* This signal is emitted to fill the list of default layouts.
|
|
|
|
*
|
|
|
|
* It is emitted on the global `tag` class rather than individual tag objects.
|
|
|
|
* The default handler is part of `rc.lua`. New modules can also use this signal
|
|
|
|
* to dynamically add new layouts to the list of default layouts.
|
|
|
|
*
|
|
|
|
* @signal request::default_layouts
|
2019-12-01 07:53:12 +01:00
|
|
|
* @tparam string context The context (currently always "startup").
|
|
|
|
* @classsignal
|
|
|
|
* @request tag default_layouts startup granted When AwesomeWM starts, it queries
|
|
|
|
* for default layout using this request.
|
2019-11-11 07:55:54 +01:00
|
|
|
* @see awful.layout.layouts
|
|
|
|
* @see awful.layout.append_default_layout
|
|
|
|
* @see awful.layout.remove_default_layout
|
|
|
|
*/
|
|
|
|
|
2019-12-01 02:11:39 +01:00
|
|
|
/** This signals is emitted when a tag needs layouts for the first time.
|
|
|
|
*
|
|
|
|
* If no handler implement it, it will fallback to the content added by
|
|
|
|
* `request::default_layouts`
|
|
|
|
*
|
|
|
|
* @signal request::layouts
|
|
|
|
* @tparam string context The context (currently always "awful").
|
|
|
|
* @tparam table hints A, currently empty, table with hints.
|
|
|
|
*/
|
2019-11-11 07:55:54 +01:00
|
|
|
|
2016-06-04 17:39:14 +02:00
|
|
|
/** When a client gets tagged with this tag.
|
|
|
|
* @signal tagged
|
2019-12-31 07:09:39 +01:00
|
|
|
* @tparam client c The tagged client.
|
2016-06-04 17:39:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** When a client gets untagged with this tag.
|
|
|
|
* @signal untagged
|
2019-12-31 07:09:39 +01:00
|
|
|
* @tparam client c The untagged client.
|
2016-06-04 17:39:14 +02:00
|
|
|
*/
|
|
|
|
|
2016-04-05 08:27:21 +02:00
|
|
|
/**
|
|
|
|
* Tag name.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2019-09-30 05:50:25 +02:00
|
|
|
* @DOC_sequences_tag_name_EXAMPLE@
|
|
|
|
*
|
2016-04-05 08:27:21 +02:00
|
|
|
* **Signal:**
|
|
|
|
*
|
|
|
|
* * *property::name*
|
|
|
|
*
|
|
|
|
* @property name
|
|
|
|
* @param string
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-01-22 15:18:07 +01:00
|
|
|
* True if the tag is selected to be viewed.
|
2016-04-05 08:27:21 +02:00
|
|
|
*
|
2019-09-30 05:50:25 +02:00
|
|
|
* @DOC_sequences_tag_selected_EXAMPLE@
|
|
|
|
*
|
2016-04-05 08:27:21 +02:00
|
|
|
* **Signal:**
|
|
|
|
*
|
|
|
|
* * *property::selected*
|
|
|
|
*
|
|
|
|
* @property selected
|
|
|
|
* @param boolean
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the tag is active and can be used.
|
|
|
|
*
|
|
|
|
* **Signal:**
|
|
|
|
*
|
|
|
|
* * *property::activated*
|
|
|
|
*
|
|
|
|
* @property activated
|
|
|
|
* @param boolean
|
2015-02-27 00:24:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** Get the number of instances.
|
|
|
|
*
|
|
|
|
* @return The number of tag objects alive.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct instances
|
2015-02-27 00:24:23 +01:00
|
|
|
*/
|
|
|
|
|
2016-04-07 06:50:54 +02:00
|
|
|
/* Set a __index metamethod for all tag instances.
|
2015-03-14 10:06:53 +01:00
|
|
|
* @tparam function cb The meta-method
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct set_index_miss_handler
|
2015-03-14 10:06:53 +01:00
|
|
|
*/
|
|
|
|
|
2016-04-07 06:50:54 +02:00
|
|
|
/* Set a __newindex metamethod for all tag instances.
|
2015-03-14 10:06:53 +01:00
|
|
|
* @tparam function cb The meta-method
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct set_newindex_miss_handler
|
2015-03-14 10:06:53 +01:00
|
|
|
*/
|
|
|
|
|
2009-07-29 17:38:48 +02:00
|
|
|
|
2009-04-11 11:45:55 +02:00
|
|
|
void
|
|
|
|
tag_unref_simplified(tag_t **tag)
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
luaA_object_unref(L, *tag);
|
2009-04-11 11:45:55 +02:00
|
|
|
}
|
|
|
|
|
2009-10-02 15:48:32 +02:00
|
|
|
static void
|
|
|
|
tag_wipe(tag_t *tag)
|
2009-04-11 11:45:55 +02:00
|
|
|
{
|
|
|
|
client_array_wipe(&tag->clients);
|
|
|
|
p_delete(&tag->name);
|
|
|
|
}
|
2008-06-18 18:31:35 +02:00
|
|
|
|
2009-07-29 17:38:48 +02:00
|
|
|
OBJECT_EXPORT_PROPERTY(tag, tag_t, selected)
|
|
|
|
OBJECT_EXPORT_PROPERTY(tag, tag_t, name)
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
/** View or unview a tag.
|
2009-07-01 16:01:44 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param udx The index of the tag on the stack.
|
2012-10-20 17:33:32 +02:00
|
|
|
* \param view Set selected or not.
|
2008-06-09 21:43:09 +02:00
|
|
|
*/
|
|
|
|
static void
|
2009-07-01 16:01:44 +02:00
|
|
|
tag_view(lua_State *L, int udx, bool view)
|
2008-06-09 21:43:09 +02:00
|
|
|
{
|
2009-08-17 15:52:41 +02:00
|
|
|
tag_t *tag = luaA_checkudata(L, udx, &tag_class);
|
2009-05-10 16:51:20 +02:00
|
|
|
if(tag->selected != view)
|
|
|
|
{
|
|
|
|
tag->selected = view;
|
2012-10-20 17:33:32 +02:00
|
|
|
banning_need_update();
|
2016-12-31 15:29:28 +01:00
|
|
|
foreach(screen, globalconf.screens)
|
|
|
|
screen_update_workarea(*screen);
|
2009-09-23 15:46:42 +02:00
|
|
|
|
|
|
|
luaA_object_emit_signal(L, udx, "property::selected", 0);
|
2009-05-02 10:43:55 +02:00
|
|
|
}
|
2008-06-09 21:43:09 +02:00
|
|
|
}
|
|
|
|
|
2009-08-11 14:40:58 +02:00
|
|
|
static void
|
2014-12-06 11:56:58 +01:00
|
|
|
tag_client_emit_signal(tag_t *t, client_t *c, const char *signame)
|
2009-08-11 14:40:58 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2009-08-11 14:40:58 +02:00
|
|
|
luaA_object_push(L, c);
|
|
|
|
luaA_object_push(L, t);
|
|
|
|
/* emit signal on client, with new tag as argument */
|
|
|
|
luaA_object_emit_signal(L, -2, signame, 1);
|
|
|
|
/* re push tag */
|
|
|
|
luaA_object_push(L, t);
|
|
|
|
/* move tag before client */
|
|
|
|
lua_insert(L, -2);
|
|
|
|
luaA_object_emit_signal(L, -2, signame, 1);
|
|
|
|
/* Remove tag */
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2009-04-11 11:45:55 +02:00
|
|
|
/** Tag a client with the tag on top of the stack.
|
2014-12-06 11:14:59 +01:00
|
|
|
* \param L The Lua VM state.
|
2008-06-09 21:43:09 +02:00
|
|
|
* \param c the client to tag
|
|
|
|
*/
|
|
|
|
void
|
2014-12-06 11:14:59 +01:00
|
|
|
tag_client(lua_State *L, client_t *c)
|
2008-06-09 21:43:09 +02:00
|
|
|
{
|
2014-12-06 11:14:59 +01:00
|
|
|
tag_t *t = luaA_object_ref_class(L, -1, &tag_class);
|
2009-04-11 11:45:55 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
/* don't tag twice */
|
|
|
|
if(is_client_tagged(c, t))
|
2009-06-10 14:24:22 +02:00
|
|
|
{
|
2014-12-06 11:14:59 +01:00
|
|
|
luaA_object_unref(L, t);
|
2008-06-09 21:43:09 +02:00
|
|
|
return;
|
2009-06-10 14:24:22 +02:00
|
|
|
}
|
2008-06-09 21:43:09 +02:00
|
|
|
|
2008-06-24 14:16:37 +02:00
|
|
|
client_array_append(&t->clients, c);
|
2009-01-02 11:55:46 +01:00
|
|
|
ewmh_client_update_desktop(c);
|
2011-03-27 19:57:06 +02:00
|
|
|
banning_need_update();
|
2016-12-31 15:35:33 +01:00
|
|
|
screen_update_workarea(c->screen);
|
2009-05-10 16:51:20 +02:00
|
|
|
|
2014-12-06 11:56:58 +01:00
|
|
|
tag_client_emit_signal(t, c, "tagged");
|
2008-06-09 21:43:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Untag a client with specified tag.
|
|
|
|
* \param c the client to tag
|
|
|
|
* \param t the tag to tag the client with
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
untag_client(client_t *c, tag_t *t)
|
|
|
|
{
|
2008-06-24 14:16:37 +02:00
|
|
|
for(int i = 0; i < t->clients.len; i++)
|
|
|
|
if(t->clients.tab[i] == c)
|
2008-06-09 21:43:09 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2008-06-24 14:16:37 +02:00
|
|
|
client_array_take(&t->clients, i);
|
2011-03-27 19:57:06 +02:00
|
|
|
banning_need_update();
|
2009-01-02 11:55:46 +01:00
|
|
|
ewmh_client_update_desktop(c);
|
2016-12-31 15:34:09 +01:00
|
|
|
screen_update_workarea(c->screen);
|
2014-12-06 11:56:58 +01:00
|
|
|
tag_client_emit_signal(t, c, "untagged");
|
|
|
|
luaA_object_unref(L, t);
|
2008-06-24 14:16:37 +02:00
|
|
|
return;
|
2008-06-09 21:43:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Check if a client is tagged with the specified tag.
|
|
|
|
* \param c the client
|
|
|
|
* \param t the tag
|
|
|
|
* \return true if the client is tagged with the tag, false otherwise.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
is_client_tagged(client_t *c, tag_t *t)
|
|
|
|
{
|
2008-06-24 14:16:37 +02:00
|
|
|
for(int i = 0; i < t->clients.len; i++)
|
2009-03-29 20:26:39 +02:00
|
|
|
if(t->clients.tab[i] == c)
|
2008-06-09 21:43:09 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-07 17:59:53 +02:00
|
|
|
/** Get the index of the tag with focused client or first selected
|
2016-05-15 15:31:57 +02:00
|
|
|
* \return Its index
|
2008-06-09 21:43:09 +02:00
|
|
|
*/
|
2009-07-30 11:29:41 +02:00
|
|
|
int
|
2016-05-15 15:31:57 +02:00
|
|
|
tags_get_current_or_first_selected_index(void)
|
2008-06-09 21:43:09 +02:00
|
|
|
{
|
2016-05-15 15:31:57 +02:00
|
|
|
/* Consider "current desktop" a tag, that has focused window,
|
|
|
|
* basically a tag user actively interacts with.
|
|
|
|
* If no focused windows are present, fallback to first selected.
|
|
|
|
*/
|
|
|
|
if(globalconf.focus.client)
|
|
|
|
{
|
|
|
|
foreach(tag, globalconf.tags)
|
|
|
|
{
|
|
|
|
if((*tag)->selected && is_client_tagged(globalconf.focus.client, *tag))
|
|
|
|
return tag_array_indexof(&globalconf.tags, tag);
|
|
|
|
}
|
|
|
|
}
|
2012-10-20 17:33:32 +02:00
|
|
|
foreach(tag, globalconf.tags)
|
2016-05-15 15:31:57 +02:00
|
|
|
{
|
2009-04-17 16:14:09 +02:00
|
|
|
if((*tag)->selected)
|
2012-10-20 17:33:32 +02:00
|
|
|
return tag_array_indexof(&globalconf.tags, tag);
|
2016-05-15 15:31:57 +02:00
|
|
|
}
|
2009-07-30 11:29:41 +02:00
|
|
|
return 0;
|
2008-06-09 21:43:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Create a new tag.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \luastack
|
2008-11-25 17:01:06 +01:00
|
|
|
* \lparam A name.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lreturn A new tag object.
|
2008-06-09 21:43:09 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_tag_new(lua_State *L)
|
|
|
|
{
|
2009-07-01 16:01:44 +02:00
|
|
|
return luaA_class_new(L, &tag_class);
|
2008-06-09 21:43:09 +02:00
|
|
|
}
|
|
|
|
|
2008-08-13 17:55:10 +02:00
|
|
|
/** Get or set the clients attached to this tag.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2019-06-08 01:08:05 +02:00
|
|
|
* @tparam[opt=nil] table clients_table None or a table of clients to set as being tagged with
|
2015-02-27 00:24:23 +01:00
|
|
|
* this tag.
|
|
|
|
* @return A table with the clients attached to this tags.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @method clients
|
2008-08-13 17:55:10 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_tag_clients(lua_State *L)
|
|
|
|
{
|
2009-08-17 15:52:41 +02:00
|
|
|
tag_t *tag = luaA_checkudata(L, 1, &tag_class);
|
2009-04-11 11:45:55 +02:00
|
|
|
client_array_t *clients = &tag->clients;
|
2008-08-13 17:55:10 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if(lua_gettop(L) == 2)
|
|
|
|
{
|
|
|
|
luaA_checktable(L, 2);
|
2009-04-11 11:45:55 +02:00
|
|
|
foreach(c, tag->clients)
|
2011-01-18 14:21:37 +01:00
|
|
|
{
|
|
|
|
/* Only untag if we aren't going to add this tag again */
|
|
|
|
bool found = false;
|
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, 2))
|
|
|
|
{
|
|
|
|
client_t *tc = luaA_checkudata(L, -1, &client_class);
|
|
|
|
/* Pop the value from lua_next */
|
|
|
|
lua_pop(L, 1);
|
|
|
|
if (tc != *c)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Pop the key from lua_next */
|
|
|
|
lua_pop(L, 1);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!found)
|
|
|
|
untag_client(*c, tag);
|
|
|
|
}
|
2008-08-13 17:55:10 +02:00
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, 2))
|
|
|
|
{
|
2009-09-30 11:55:43 +02:00
|
|
|
client_t *c = luaA_checkudata(L, -1, &client_class);
|
2009-04-11 11:45:55 +02:00
|
|
|
/* push tag on top of the stack */
|
|
|
|
lua_pushvalue(L, 1);
|
2014-12-06 11:14:59 +01:00
|
|
|
tag_client(L, c);
|
2008-08-13 17:55:10 +02:00
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
}
|
2008-08-17 07:52:04 +02:00
|
|
|
|
2009-03-14 13:33:52 +01:00
|
|
|
lua_createtable(L, clients->len, 0);
|
2008-08-17 07:52:04 +02:00
|
|
|
for(i = 0; i < clients->len; i++)
|
2008-08-13 17:55:10 +02:00
|
|
|
{
|
2009-06-29 11:02:13 +02:00
|
|
|
luaA_object_push(L, clients->tab[i]);
|
2008-08-17 07:52:04 +02:00
|
|
|
lua_rawseti(L, -2, i + 1);
|
2008-08-13 17:55:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-07-01 16:01:44 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(tag, tag_t, name, lua_pushstring)
|
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(tag, tag_t, selected, lua_pushboolean)
|
2012-10-20 17:33:32 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(tag, tag_t, activated, lua_pushboolean)
|
2009-07-01 16:01:44 +02:00
|
|
|
|
|
|
|
/** Set the tag name.
|
2008-07-01 11:38:40 +02:00
|
|
|
* \param L The Lua VM state.
|
2009-08-25 04:55:10 +02:00
|
|
|
* \param tag The tag to name.
|
2008-07-01 11:38:40 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
2009-07-01 16:01:44 +02:00
|
|
|
luaA_tag_set_name(lua_State *L, tag_t *tag)
|
2008-07-01 11:38:40 +02:00
|
|
|
{
|
2017-05-07 17:59:53 +02:00
|
|
|
const char *buf = luaL_checkstring(L, -1);
|
2009-07-01 16:01:44 +02:00
|
|
|
p_delete(&tag->name);
|
2017-05-07 17:59:53 +02:00
|
|
|
tag->name = a_strdup(buf);
|
2009-07-01 16:01:44 +02:00
|
|
|
luaA_object_emit_signal(L, -3, "property::name", 0);
|
2012-10-20 17:33:32 +02:00
|
|
|
ewmh_update_net_desktop_names();
|
2009-07-01 16:01:44 +02:00
|
|
|
return 0;
|
2008-07-01 11:38:40 +02:00
|
|
|
}
|
|
|
|
|
2009-07-01 16:01:44 +02:00
|
|
|
/** Set the tag selection status.
|
2008-07-01 11:38:40 +02:00
|
|
|
* \param L The Lua VM state.
|
2009-08-25 04:55:10 +02:00
|
|
|
* \param tag The tag to set the selection status for.
|
2008-07-01 11:38:40 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
2009-07-01 16:01:44 +02:00
|
|
|
luaA_tag_set_selected(lua_State *L, tag_t *tag)
|
2008-07-01 11:38:40 +02:00
|
|
|
{
|
2009-07-01 16:01:44 +02:00
|
|
|
tag_view(L, -3, luaA_checkboolean(L, -1));
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-01 11:38:40 +02:00
|
|
|
|
2012-10-20 17:33:32 +02:00
|
|
|
/** Set the tag activated status.
|
2009-07-01 16:01:44 +02:00
|
|
|
* \param L The Lua VM state.
|
2012-10-20 17:33:32 +02:00
|
|
|
* \param tag The tag to set the activated status for.
|
2009-07-01 16:01:44 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
2012-10-20 17:33:32 +02:00
|
|
|
luaA_tag_set_activated(lua_State *L, tag_t *tag)
|
2009-07-01 16:01:44 +02:00
|
|
|
{
|
2012-10-20 17:33:32 +02:00
|
|
|
bool activated = luaA_checkboolean(L, -1);
|
|
|
|
if(activated == tag->activated)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tag->activated = activated;
|
|
|
|
if(activated)
|
2008-07-01 11:38:40 +02:00
|
|
|
{
|
2012-10-20 17:33:32 +02:00
|
|
|
lua_pushvalue(L, -3);
|
|
|
|
tag_array_append(&globalconf.tags, luaA_object_ref_class(L, -1, &tag_class));
|
2009-07-01 16:01:44 +02:00
|
|
|
}
|
2012-10-20 17:33:32 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < globalconf.tags.len; i++)
|
|
|
|
if(globalconf.tags.tab[i] == tag)
|
|
|
|
{
|
|
|
|
tag_array_take(&globalconf.tags, i);
|
|
|
|
break;
|
|
|
|
}
|
2008-11-25 17:01:06 +01:00
|
|
|
|
2012-10-20 17:33:32 +02:00
|
|
|
if (tag->selected)
|
|
|
|
{
|
|
|
|
tag->selected = false;
|
|
|
|
luaA_object_emit_signal(L, -3, "property::selected", 0);
|
|
|
|
banning_need_update();
|
|
|
|
}
|
|
|
|
luaA_object_unref(L, tag);
|
|
|
|
}
|
|
|
|
ewmh_update_net_numbers_of_desktop();
|
|
|
|
ewmh_update_net_desktop_names();
|
2008-07-24 17:06:52 +02:00
|
|
|
|
2012-10-20 17:33:32 +02:00
|
|
|
luaA_object_emit_signal(L, -3, "property::activated", 0);
|
2008-07-01 11:38:40 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-01 16:01:44 +02:00
|
|
|
void
|
|
|
|
tag_class_setup(lua_State *L)
|
2008-06-09 21:43:09 +02:00
|
|
|
{
|
2012-06-06 23:07:07 +02:00
|
|
|
static const struct luaL_Reg tag_methods[] =
|
2009-07-01 16:01:44 +02:00
|
|
|
{
|
|
|
|
LUA_CLASS_METHODS(tag)
|
|
|
|
{ "__call", luaA_tag_new },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2012-06-06 23:07:07 +02:00
|
|
|
static const struct luaL_Reg tag_meta[] =
|
2009-07-01 16:01:44 +02:00
|
|
|
{
|
|
|
|
LUA_OBJECT_META(tag)
|
|
|
|
LUA_CLASS_META
|
|
|
|
{ "clients", luaA_tag_clients },
|
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
|
|
|
|
2009-09-30 14:21:25 +02:00
|
|
|
luaA_class_setup(L, &tag_class, "tag", NULL,
|
2009-10-02 15:48:32 +02:00
|
|
|
(lua_class_allocator_t) tag_new,
|
|
|
|
(lua_class_collector_t) tag_wipe,
|
|
|
|
NULL,
|
2009-08-20 17:37:46 +02:00
|
|
|
luaA_class_index_miss_property, luaA_class_newindex_miss_property,
|
2009-07-01 16:01:44 +02:00
|
|
|
tag_methods, tag_meta);
|
2010-09-01 15:41:41 +02:00
|
|
|
luaA_class_add_property(&tag_class, "name",
|
2009-07-01 16:01:44 +02:00
|
|
|
(lua_class_propfunc_t) luaA_tag_set_name,
|
|
|
|
(lua_class_propfunc_t) luaA_tag_get_name,
|
|
|
|
(lua_class_propfunc_t) luaA_tag_set_name);
|
2010-09-01 15:41:41 +02:00
|
|
|
luaA_class_add_property(&tag_class, "selected",
|
2009-07-01 16:01:44 +02:00
|
|
|
(lua_class_propfunc_t) luaA_tag_set_selected,
|
|
|
|
(lua_class_propfunc_t) luaA_tag_get_selected,
|
|
|
|
(lua_class_propfunc_t) luaA_tag_set_selected);
|
2012-10-20 17:33:32 +02:00
|
|
|
luaA_class_add_property(&tag_class, "activated",
|
|
|
|
(lua_class_propfunc_t) luaA_tag_set_activated,
|
|
|
|
(lua_class_propfunc_t) luaA_tag_get_activated,
|
|
|
|
(lua_class_propfunc_t) luaA_tag_set_activated);
|
2009-07-01 16:01:44 +02:00
|
|
|
}
|
2008-07-10 09:22:23 +02:00
|
|
|
|
2017-10-21 01:54:36 +02:00
|
|
|
/* @DOC_cobject_COMMON@ */
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|