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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** awesome tag API
|
|
|
|
*
|
|
|
|
* Furthermore to the classes described here, one can also use signals as
|
|
|
|
* described in @{signals}.
|
|
|
|
*
|
2016-04-07 05:13:13 +02:00
|
|
|
* ![Client geometry](../images/tag_props.svg)
|
|
|
|
*
|
2016-12-20 02:39:40 +01:00
|
|
|
* **Creating tags**:
|
|
|
|
*
|
|
|
|
* 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,
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* awful.tag.add("Second tag", {
|
|
|
|
* icon = "/path/to/icon2.png",
|
|
|
|
* layout = awful.layout.suit.max,
|
|
|
|
* screen = s,
|
|
|
|
* }
|
|
|
|
*
|
2016-12-20 02:40:14 +01:00
|
|
|
* **Accessing tags**:
|
|
|
|
*
|
|
|
|
* 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")
|
|
|
|
*
|
2016-12-20 02:40:34 +01:00
|
|
|
* **Common shortcuts**:
|
|
|
|
*
|
|
|
|
* 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()
|
|
|
|
* awful.tag.add("NewTag",{screen= awful.screen.focused() }):view_only()
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @author Julien Danjou <julien@danjou.info>
|
|
|
|
* @copyright 2008-2009 Julien Danjou
|
|
|
|
* @classmod tag
|
|
|
|
*/
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
#include "tag.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
|
|
|
|
2016-06-04 17:39:14 +02:00
|
|
|
/**
|
|
|
|
* @signal request::select
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** When a client gets tagged with this tag.
|
|
|
|
* @signal tagged
|
|
|
|
* @client c The tagged client.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** When a client gets untagged with this tag.
|
|
|
|
* @signal untagged
|
|
|
|
* @client c The untagged client.
|
|
|
|
*/
|
|
|
|
|
2016-04-05 08:27:21 +02:00
|
|
|
/**
|
|
|
|
* Tag name.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2016-04-05 08:27:21 +02:00
|
|
|
* **Signal:**
|
|
|
|
*
|
|
|
|
* * *property::name*
|
|
|
|
*
|
|
|
|
* @property name
|
|
|
|
* @param string
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the tag is selected to be viewed
|
|
|
|
*
|
|
|
|
* **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.
|
|
|
|
* @function instances
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
* @function set_index_miss_handler
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
* @function set_newindex_miss_handler
|
|
|
|
*/
|
|
|
|
|
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();
|
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();
|
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);
|
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;
|
|
|
|
}
|
|
|
|
|
2016-05-15 15:31:57 +02:00
|
|
|
/** Get the index of the tag with focused client or first selected
|
|
|
|
* \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
|
|
|
*
|
|
|
|
* @param clients_table None or a table of clients to set as being tagged with
|
|
|
|
* this tag.
|
|
|
|
* @return A table with the clients attached to this tags.
|
|
|
|
* @function 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
|
|
|
{
|
|
|
|
size_t len;
|
2009-07-01 16:01:44 +02:00
|
|
|
const char *buf = luaL_checklstring(L, -1, &len);
|
|
|
|
p_delete(&tag->name);
|
|
|
|
a_iso2utf8(buf, len, &tag->name, NULL);
|
|
|
|
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
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|