[lua] Remove regex matching
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
fb822997b3
commit
ccb2a2db77
10
awful.lua
10
awful.lua
|
@ -40,7 +40,7 @@ end
|
|||
-- set i to 1 to get next, -1 to get previous.
|
||||
function client_next(i)
|
||||
-- Get all visible clients
|
||||
local cls = client.visible_get(mouse.screen_get(), ".*")
|
||||
local cls = client.visible_get(mouse.screen_get())
|
||||
-- Get currently focused client
|
||||
local sel = client.focus_get()
|
||||
if not sel then return end
|
||||
|
@ -94,7 +94,7 @@ end
|
|||
function getselectedtags()
|
||||
local idx = 1
|
||||
local screen = mouse.screen_get()
|
||||
local tags = tag.get(screen, ".*")
|
||||
local tags = tag.get(screen)
|
||||
local vtags = {}
|
||||
for i, t in ipairs(tags) do
|
||||
if t:isselected() then
|
||||
|
@ -161,14 +161,14 @@ end
|
|||
|
||||
-- View no tag
|
||||
function tag_viewnone()
|
||||
local tags = tag.get(mouse.screen_get(), ".*")
|
||||
local tags = tag.get(mouse.screen_get())
|
||||
for i, t in ipairs(tags) do
|
||||
t:view(false)
|
||||
end
|
||||
end
|
||||
|
||||
function tag_viewidx(r)
|
||||
local tags = tag.get(mouse.screen_get(), ".*")
|
||||
local tags = tag.get(mouse.screen_get())
|
||||
local sel = getselectedtag()
|
||||
tag_viewnone()
|
||||
for i, t in ipairs(tags) do
|
||||
|
@ -202,7 +202,7 @@ end
|
|||
|
||||
function client_movetotag(target, c)
|
||||
local sel = c or client.focus_get();
|
||||
local tags = tag.get(mouse.screen_get(), ".*")
|
||||
local tags = tag.get(mouse.screen_get())
|
||||
for i, t in ipairs(tags) do
|
||||
sel:tag(t, false)
|
||||
end
|
||||
|
|
48
client.c
48
client.c
|
@ -783,7 +783,7 @@ client_kill(client_t *c)
|
|||
|
||||
ev.data.data32[0] = xutil_intern_atom_reply(globalconf.connection, &globalconf.atoms,
|
||||
xutil_intern_atom(globalconf.connection,
|
||||
&globalconf.atoms,
|
||||
&globalconf.atoms,
|
||||
"WM_DELETE_WINDOW"));
|
||||
ev.data.data32[1] = XCB_CURRENT_TIME;
|
||||
|
||||
|
@ -797,30 +797,19 @@ client_kill(client_t *c)
|
|||
static int
|
||||
luaA_client_get(lua_State *L)
|
||||
{
|
||||
int ret, i = 1;
|
||||
regex_t r;
|
||||
regmatch_t match;
|
||||
int i = 1;
|
||||
client_t *c, **cobj;
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
char error[512];
|
||||
|
||||
if((ret = regcomp(&r, name, REG_EXTENDED)))
|
||||
{
|
||||
regerror(ret, &r, error, sizeof(error));
|
||||
luaL_error(L, "regex compilation error: %s\n", error);
|
||||
}
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(!regexec(&r, c->name, 1, &match, 0))
|
||||
{
|
||||
cobj = lua_newuserdata(L, sizeof(client_t *));
|
||||
*cobj = c;
|
||||
luaA_settype(L, "client");
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
|
||||
{
|
||||
cobj = lua_newuserdata(L, sizeof(client_t *));
|
||||
*cobj = c;
|
||||
luaA_settype(L, "client");
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -857,34 +846,23 @@ luaA_client_mouse(lua_State *L)
|
|||
static int
|
||||
luaA_client_visible_get(lua_State *L)
|
||||
{
|
||||
int ret, i = 1;
|
||||
regex_t r;
|
||||
regmatch_t match;
|
||||
int i = 1;
|
||||
client_t *c, **cobj;
|
||||
char error[512];
|
||||
int screen = luaL_checknumber(L, 1) - 1;
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
|
||||
luaA_checkscreen(screen);
|
||||
|
||||
if((ret = regcomp(&r, name, REG_EXTENDED)))
|
||||
{
|
||||
regerror(ret, &r, error, sizeof(error));
|
||||
luaL_error(L, "regex compilation error: %s\n", error);
|
||||
}
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(!c->skip && client_isvisible(c, screen)
|
||||
&& !regexec(&r, c->name, 1, &match, 0))
|
||||
if(!c->skip && client_isvisible(c, screen))
|
||||
{
|
||||
cobj = lua_newuserdata(L, sizeof(client_t *));
|
||||
*cobj = c;
|
||||
luaA_settype(L, "client");
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1006,7 +984,7 @@ luaA_client_coords_set(lua_State *L)
|
|||
{
|
||||
client_t **c = luaL_checkudata(L, 1, "client");
|
||||
area_t geometry;
|
||||
|
||||
|
||||
if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
|
||||
{
|
||||
luaA_checktable(L, 2);
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
#include <xcb/xcb_event.h>
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "layout.h"
|
||||
#include "common/draw.h"
|
||||
|
|
27
tag.c
27
tag.c
|
@ -268,32 +268,21 @@ static int
|
|||
luaA_tag_get(lua_State *L)
|
||||
{
|
||||
int screen = luaL_checknumber(L, 1) - 1;
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
tag_t *tag, **tobj;
|
||||
int ret, i = 1;
|
||||
regex_t r;
|
||||
regmatch_t match;
|
||||
char error[512];
|
||||
int i = 1;
|
||||
|
||||
luaA_checkscreen(screen);
|
||||
|
||||
if((ret = regcomp(&r, name, REG_EXTENDED)))
|
||||
{
|
||||
regerror(ret, &r, error, sizeof(error));
|
||||
luaL_error(L, "regex compilation error: %s\n", error);
|
||||
}
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
|
||||
if(!regexec(&r, tag->name, 1, &match, 0))
|
||||
{
|
||||
tobj = lua_newuserdata(L, sizeof(tag_t *));
|
||||
*tobj = tag;
|
||||
tag_ref(&tag);
|
||||
luaA_settype(L, "tag");
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
{
|
||||
tobj = lua_newuserdata(L, sizeof(tag_t *));
|
||||
*tobj = tag;
|
||||
tag_ref(&tag);
|
||||
luaA_settype(L, "tag");
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
49
widget.c
49
widget.c
|
@ -295,50 +295,39 @@ luaA_widget_eq(lua_State *L)
|
|||
static int
|
||||
luaA_widget_get(lua_State *L)
|
||||
{
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
statusbar_t *sb;
|
||||
widget_t **wobj;
|
||||
widget_node_t *widget;
|
||||
int ret, i = 1, screen;
|
||||
regex_t r;
|
||||
regmatch_t match;
|
||||
char error[512];
|
||||
int i = 1, screen;
|
||||
bool add = true;
|
||||
widget_node_t *wlist = NULL, *witer;
|
||||
|
||||
if((ret = regcomp(&r, name, REG_EXTENDED)))
|
||||
{
|
||||
regerror(ret, &r, error, sizeof(error));
|
||||
luaL_error(L, "regex compilation error: %s\n", error);
|
||||
}
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
||||
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
||||
for(widget = sb->widgets; widget; widget = widget->next)
|
||||
if(!regexec(&r, widget->widget->name, 1, &match, 0))
|
||||
{
|
||||
for(witer = wlist; witer; witer = witer->next)
|
||||
if(witer->widget == widget->widget)
|
||||
{
|
||||
add = false;
|
||||
break;
|
||||
}
|
||||
if(add)
|
||||
{
|
||||
for(witer = wlist; witer; witer = witer->next)
|
||||
if(witer->widget == widget->widget)
|
||||
{
|
||||
witer = p_new(widget_node_t, 1);
|
||||
wobj = lua_newuserdata(L, sizeof(tag_t *));
|
||||
witer->widget = *wobj = widget->widget;
|
||||
widget_ref(&widget->widget);
|
||||
widget_node_list_push(&wlist, witer);
|
||||
/* ref again for the list */
|
||||
widget_ref(&widget->widget);
|
||||
luaA_settype(L, "widget");
|
||||
lua_rawseti(L, -2, i++);
|
||||
add = false;
|
||||
break;
|
||||
}
|
||||
add = true;
|
||||
if(add)
|
||||
{
|
||||
witer = p_new(widget_node_t, 1);
|
||||
wobj = lua_newuserdata(L, sizeof(tag_t *));
|
||||
witer->widget = *wobj = widget->widget;
|
||||
widget_ref(&widget->widget);
|
||||
widget_node_list_push(&wlist, witer);
|
||||
/* ref again for the list */
|
||||
widget_ref(&widget->widget);
|
||||
luaA_settype(L, "widget");
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
add = true;
|
||||
}
|
||||
|
||||
widget_node_list_wipe(&wlist);
|
||||
|
||||
|
|
Loading…
Reference in New Issue