focus: remove focus history

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-31 15:51:28 +02:00
parent 1cc071e24f
commit 81ae462a70
14 changed files with 39 additions and 179 deletions

View File

@ -43,7 +43,6 @@ set(AWE_SRCS
${SOURCE_DIR}/dbus.c ${SOURCE_DIR}/dbus.c
${SOURCE_DIR}/event.c ${SOURCE_DIR}/event.c
${SOURCE_DIR}/ewmh.c ${SOURCE_DIR}/ewmh.c
${SOURCE_DIR}/focus.c
${SOURCE_DIR}/keybinding.c ${SOURCE_DIR}/keybinding.c
${SOURCE_DIR}/keygrabber.c ${SOURCE_DIR}/keygrabber.c
${SOURCE_DIR}/layout.c ${SOURCE_DIR}/layout.c

View File

@ -29,9 +29,10 @@
#include <ev.h> #include <ev.h>
#include "client.h"
#include "titlebar.h"
#include "event.h" #include "event.h"
#include "window.h" #include "window.h"
#include "focus.h"
#include "ewmh.h" #include "ewmh.h"
#include "dbus.h" #include "dbus.h"
#include "statusbar.h" #include "statusbar.h"
@ -406,8 +407,7 @@ main(int argc, char **argv)
/* init screens struct */ /* init screens struct */
globalconf.screens_info = screensinfo_new(globalconf.connection); globalconf.screens_info = screensinfo_new(globalconf.connection);
globalconf.screens = p_new(screen_t, globalconf.screens_info->nscreen); globalconf.screen_focus = globalconf.screens = p_new(screen_t, globalconf.screens_info->nscreen);
focus_client_push(NULL);
/* init default font and colors */ /* init default font and colors */
globalconf.font = draw_font_new(globalconf.connection, globalconf.default_screen, "sans 8"); globalconf.font = draw_font_new(globalconf.connection, globalconf.default_screen, "sans 8");

View File

@ -353,6 +353,12 @@ function hook_arrange(screen)
-- Update tag history -- Update tag history
awful.tag.history.update(screen) awful.tag.history.update(screen)
-- If no window has focus, give focus to the first one
if not client.focus_get() then
local vc = client.visible_get(screen)
if #vc > 0 then vc[1]:focus_set() end
end
-- Uncomment if you want mouse warping -- Uncomment if you want mouse warping
--[[ --[[
local sel = client.focus_get() local sel = client.focus_get()

View File

@ -28,7 +28,6 @@
#include "client.h" #include "client.h"
#include "tag.h" #include "tag.h"
#include "window.h" #include "window.h"
#include "focus.h"
#include "ewmh.h" #include "ewmh.h"
#include "widget.h" #include "widget.h"
#include "screen.h" #include "screen.h"
@ -182,7 +181,7 @@ client_updatetitle(client_t *c)
static void static void
client_unfocus(client_t *c) client_unfocus(client_t *c)
{ {
focus_client_push(NULL); globalconf.screens[c->screen].client_focus = NULL;
/* Call hook */ /* Call hook */
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
@ -198,7 +197,7 @@ client_unfocus(client_t *c)
void void
client_ban(client_t *c) client_ban(client_t *c)
{ {
if(globalconf.focus->client == c) if(globalconf.screen_focus->client_focus == c)
client_unfocus(c); client_unfocus(c);
xcb_unmap_window(globalconf.connection, c->win); xcb_unmap_window(globalconf.connection, c->win);
if(c->ishidden) if(c->ishidden)
@ -221,20 +220,22 @@ client_focus(client_t *c, int screen)
/* if c is NULL or invisible, take next client in the focus history */ /* if c is NULL or invisible, take next client in the focus history */
if((!c || (c && (!client_isvisible(c, screen)))) if((!c || (c && (!client_isvisible(c, screen))))
&& !(c = focus_get_current_client(screen))) && !(c = globalconf.screens[screen].client_focus))
/* if c is still NULL take next client in the stack */ /* if c is still NULL take next client in the stack */
for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next); for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
/* unfocus current selected client */ /* unfocus current selected client */
if(globalconf.focus->client && c != globalconf.focus->client) if(globalconf.screen_focus->client_focus && c != globalconf.screen_focus->client_focus)
client_unfocus(globalconf.focus->client); client_unfocus(globalconf.screen_focus->client_focus);
if(c) if(c)
{ {
/* unban the client before focusing or it will fail */ /* unban the client before focusing or it will fail */
client_unban(c); client_unban(c);
/* save sel in focus history */
focus_client_push(c); globalconf.screen_focus = &globalconf.screens[c->screen];
globalconf.screen_focus->client_focus = c;
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT, xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
c->win, XCB_CURRENT_TIME); c->win, XCB_CURRENT_TIME);
phys_screen = c->phys_screen; phys_screen = c->phys_screen;
@ -243,7 +244,7 @@ client_focus(client_t *c, int screen)
globalconf.screens[c->screen].need_arrange = true; globalconf.screens[c->screen].need_arrange = true;
/* execute hook */ /* execute hook */
luaA_client_userdata_new(globalconf.L, globalconf.focus->client); luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0); luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
} }
else else
@ -424,8 +425,6 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
/* Push client in client list */ /* Push client in client list */
client_list_push(&globalconf.clients, c); client_list_push(&globalconf.clients, c);
/* Append client in history: it'll be last. */
focus_client_append(c);
client_ref(&c); client_ref(&c);
/* Push client in stack */ /* Push client in stack */
client_raise(c); client_raise(c);
@ -679,9 +678,6 @@ client_unmanage(client_t *c)
luaA_client_userdata_new(globalconf.L, c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0); luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
if(globalconf.focus->client == c)
client_focus(NULL, c->screen);
/* The server grab construct avoids race conditions. */ /* The server grab construct avoids race conditions. */
xcb_grab_server(globalconf.connection); xcb_grab_server(globalconf.connection);
@ -691,7 +687,6 @@ client_unmanage(client_t *c)
/* remove client everywhere */ /* remove client everywhere */
client_list_detach(&globalconf.clients, c); client_list_detach(&globalconf.clients, c);
focus_client_delete(c);
stack_client_delete(c); stack_client_delete(c);
for(int i = 0; i < tags->len; i++) for(int i = 0; i < tags->len; i++)
untag_client(c, tags->tab[i]); untag_client(c, tags->tab[i]);
@ -921,10 +916,10 @@ luaA_client_visible_get(lua_State *L)
* \lreturn The currently focused client. * \lreturn The currently focused client.
*/ */
static int static int
luaA_client_focus_get(lua_State *L __attribute__ ((unused))) luaA_client_focus_get(lua_State *L)
{ {
if(globalconf.focus->client) if(globalconf.screen_focus->client_focus)
return luaA_client_userdata_new(globalconf.L, globalconf.focus->client); return luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
return 0; return 0;
} }

8
ewmh.c
View File

@ -27,7 +27,6 @@
#include "ewmh.h" #include "ewmh.h"
#include "tag.h" #include "tag.h"
#include "focus.h"
#include "screen.h" #include "screen.h"
#include "client.h" #include "client.h"
#include "widget.h" #include "widget.h"
@ -235,9 +234,12 @@ void
ewmh_update_net_active_window(int phys_screen) ewmh_update_net_active_window(int phys_screen)
{ {
xcb_window_t win; xcb_window_t win;
client_t *sel = focus_get_current_client(phys_screen);
win = sel ? sel->win : XCB_NONE; if(globalconf.screen_focus->client_focus
&& globalconf.screen_focus->client_focus->phys_screen == phys_screen)
win = globalconf.screen_focus->client_focus->win;
else
win = XCB_NONE;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
xutil_screen_get(globalconf.connection, phys_screen)->root, xutil_screen_get(globalconf.connection, phys_screen)->root,

93
focus.c
View File

@ -1,93 +0,0 @@
/*
* focus.c - focus 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.
*
*/
#include "focus.h"
#include "cnode.h"
#include "tag.h"
extern awesome_t globalconf;
/** Push the client at the beginning of the client focus history stack.
* \param c The client to push.
*/
void
focus_client_push(client_t *c)
{
client_node_t *node = client_node_client_add(&globalconf.focus, c);
client_node_list_push(&globalconf.focus, node);
}
/** Append the client at the end of the client focus history stack.
* \param c The client to append.
*/
void
focus_client_append(client_t *c)
{
client_node_t *node = client_node_client_add(&globalconf.focus, c);
client_node_list_append(&globalconf.focus, node);
}
/** Remove a client from focus history.
* \param c The client.
*/
void
focus_client_delete(client_t *c)
{
client_node_t *node = client_node_client_getby(globalconf.focus, c);
if(node)
{
client_node_list_detach(&globalconf.focus, node);
p_delete(&node);
}
}
static client_t *
focus_get_latest_client_for_tags(tag_t **t, int nindex)
{
client_node_t *node;
tag_t **tags;
int i = 0;
for(node = globalconf.focus; node; node = node->next)
if(node->client && !node->client->skip && !node->client->ishidden)
for(tags = t; *tags; tags++)
if(is_client_tagged(node->client, *tags))
if(i-- == nindex)
return node->client;
return NULL;
}
/** Get the latest focused client on a screen.
* \param screen The virtual screen number.
* \return A pointer to an existing client.
*/
client_t *
focus_get_current_client(int screen)
{
tag_t **curtags = tags_get_current(screen);
client_t *sel = focus_get_latest_client_for_tags(curtags, 0);
p_delete(&curtags);
return sel;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

33
focus.h
View File

@ -1,33 +0,0 @@
/*
* focus.h - focus management header
*
* 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.
*
*/
#ifndef AWESOME_FOCUS_H
#define AWESOME_FOCUS_H
#include "client.h"
void focus_client_push(client_t *);
void focus_client_append(client_t *);
void focus_client_delete(client_t *);
client_t * focus_get_current_client(int);
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -19,8 +19,8 @@
* *
*/ */
#include "client.h"
#include "tag.h" #include "tag.h"
#include "focus.h"
#include "window.h" #include "window.h"
#include "screen.h" #include "screen.h"
@ -34,7 +34,7 @@ arrange(int screen)
{ {
client_t *c; client_t *c;
layout_t *curlay = layout_get_current(screen); layout_t *curlay = layout_get_current(screen);
int fscreen, phys_screen = screen_virttophys(screen); int phys_screen = screen_virttophys(screen);
xcb_query_pointer_cookie_t qp_c; xcb_query_pointer_cookie_t qp_c;
xcb_query_pointer_reply_t *qp_r; xcb_query_pointer_reply_t *qp_r;
@ -65,20 +65,6 @@ arrange(int screen)
globalconf.pointer_x = qp_r->root_x; globalconf.pointer_x = qp_r->root_x;
globalconf.pointer_y = qp_r->root_y; globalconf.pointer_y = qp_r->root_y;
/* no window have focus, let's try to see if mouse is on
* the screen we just rearranged */
if(!globalconf.focus->client)
{
fscreen = screen_get_bycoord(globalconf.screens_info,
screen,
qp_r->root_x, qp_r->root_y);
/* if the mouse in on the same screen we just rearranged, and no
* client are currently focused, pick the first one in history */
if(fscreen == screen
&& (c = focus_get_current_client(screen)))
client_focus(c, screen);
}
p_delete(&qp_r); p_delete(&qp_r);
} }

View File

@ -22,7 +22,6 @@
#include "client.h" #include "client.h"
#include "tag.h" #include "tag.h"
#include "screen.h" #include "screen.h"
#include "focus.h"
#include "layouts/magnifier.h" #include "layouts/magnifier.h"
extern awesome_t globalconf; extern awesome_t globalconf;
@ -37,7 +36,7 @@ layout_magnifier(int screen)
globalconf.screens[screen].statusbar, globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding); &globalconf.screens[screen].padding);
focus = focus_get_current_client(screen); focus = globalconf.screens[screen].client_focus;
/* If focused window is not tiled, take the first one which is tiled. */ /* If focused window is not tiled, take the first one which is tiled. */
if(!IS_TILED(focus, screen)) if(!IS_TILED(focus, screen))

View File

@ -22,7 +22,6 @@
#include "tag.h" #include "tag.h"
#include "screen.h" #include "screen.h"
#include "client.h" #include "client.h"
#include "focus.h"
#include "layouts/max.h" #include "layouts/max.h"
extern awesome_t globalconf; extern awesome_t globalconf;
@ -30,7 +29,7 @@ extern awesome_t globalconf;
void void
layout_max(int screen) layout_max(int screen)
{ {
client_t *c, *focus; client_t *c;
area_t area = screen_area_get(screen, area_t area = screen_area_get(screen,
globalconf.screens[screen].statusbar, globalconf.screens[screen].statusbar,
&globalconf.screens[screen].padding); &globalconf.screens[screen].padding);
@ -45,8 +44,7 @@ layout_max(int screen)
area.height += 2 * c->border; area.height += 2 * c->border;
} }
if((focus = focus_get_current_client(screen)) if(IS_TILED(globalconf.screens[screen].client_focus, screen))
&& IS_TILED(focus, screen)) client_raise(globalconf.screens[screen].client_focus);
client_raise(focus);
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -26,7 +26,6 @@
#include "screen.h" #include "screen.h"
#include "tag.h" #include "tag.h"
#include "focus.h"
#include "client.h" #include "client.h"
#include "layouts/floating.h" #include "layouts/floating.h"

View File

@ -372,6 +372,8 @@ typedef struct
xcb_window_t window; xcb_window_t window;
bool has_systray_widget; bool has_systray_widget;
} systray; } systray;
/** Focused client */
client_t *client_focus;
} screen_t; } screen_t;
/** Main configuration structure */ /** Main configuration structure */
@ -410,8 +412,6 @@ struct awesome_t
xembed_window_t *embedded; xembed_window_t *embedded;
/** Path to config file */ /** Path to config file */
char *configpath; char *configpath;
/** Selected clients history */
client_node_t *focus;
/** Stack client history */ /** Stack client history */
client_node_t *stack; client_node_t *stack;
/** Command line passed to awesome */ /** Command line passed to awesome */
@ -454,6 +454,8 @@ struct awesome_t
struct ev_timer timer; struct ev_timer timer;
/** The key grabber function */ /** The key grabber function */
luaA_function keygrabber; luaA_function keygrabber;
/** Focused screen */
screen_t *screen_focus;
}; };
#endif #endif

View File

@ -48,7 +48,7 @@ appicon_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
switch(type) switch(type)
{ {
case AWESOME_TYPE_STATUSBAR: case AWESOME_TYPE_STATUSBAR:
c = globalconf.focus->client; c = globalconf.screen_focus->client_focus;
break; break;
case AWESOME_TYPE_TITLEBAR: case AWESOME_TYPE_TITLEBAR:
c = client_getbytitlebar(p); c = client_getbytitlebar(p);

View File

@ -19,8 +19,8 @@
* *
*/ */
#include "client.h"
#include "widget.h" #include "widget.h"
#include "focus.h"
#include "ewmh.h" #include "ewmh.h"
#include "tag.h" #include "tag.h"
#include "common/markup.h" #include "common/markup.h"