2008-05-25 19:30:54 +02:00
|
|
|
/*
|
|
|
|
* stack.c - client stack management
|
|
|
|
*
|
2009-04-17 23:26:26 +02:00
|
|
|
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
|
2008-05-25 19:30:54 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-04-17 23:26:26 +02:00
|
|
|
#include "stack.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "ewmh.h"
|
2009-09-14 20:22:12 +02:00
|
|
|
#include "objects/client.h"
|
2010-10-06 13:35:14 +02:00
|
|
|
#include "objects/drawin.h"
|
2009-04-17 23:26:26 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
stack_client_remove(client_t *c)
|
|
|
|
{
|
|
|
|
foreach(client, globalconf.stack)
|
|
|
|
if(*client == c)
|
|
|
|
{
|
|
|
|
client_array_remove(&globalconf.stack, client);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-16 13:47:40 +02:00
|
|
|
ewmh_update_net_client_list_stacking();
|
2009-10-07 15:25:18 +02:00
|
|
|
stack_windows();
|
2009-04-17 23:26:26 +02:00
|
|
|
}
|
2008-05-25 19:30:54 +02:00
|
|
|
|
2008-11-12 11:23:28 +01:00
|
|
|
/** Push the client at the beginning of the client stack.
|
2008-05-25 19:30:54 +02:00
|
|
|
* \param c The client to push.
|
|
|
|
*/
|
|
|
|
void
|
2009-08-24 15:07:58 +02:00
|
|
|
stack_client_push(client_t *c)
|
2008-05-25 19:30:54 +02:00
|
|
|
{
|
2009-04-17 23:26:26 +02:00
|
|
|
stack_client_remove(c);
|
|
|
|
client_array_push(&globalconf.stack, c);
|
2010-08-16 13:47:40 +02:00
|
|
|
ewmh_update_net_client_list_stacking();
|
2009-10-07 15:25:18 +02:00
|
|
|
stack_windows();
|
2008-05-25 19:30:54 +02:00
|
|
|
}
|
|
|
|
|
2008-11-12 11:23:28 +01:00
|
|
|
/** Push the client at the end of the client stack.
|
|
|
|
* \param c The client to push.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
stack_client_append(client_t *c)
|
|
|
|
{
|
2009-04-17 23:26:26 +02:00
|
|
|
stack_client_remove(c);
|
|
|
|
client_array_append(&globalconf.stack, c);
|
2010-08-16 13:47:40 +02:00
|
|
|
ewmh_update_net_client_list_stacking();
|
2009-10-07 15:25:18 +02:00
|
|
|
stack_windows();
|
2008-11-12 11:23:28 +01:00
|
|
|
}
|
|
|
|
|
2009-10-05 20:36:02 +02:00
|
|
|
static bool need_stack_refresh = false;
|
|
|
|
|
|
|
|
void
|
|
|
|
stack_windows(void)
|
|
|
|
{
|
|
|
|
need_stack_refresh = true;
|
|
|
|
}
|
|
|
|
|
2010-07-31 10:40:01 +02:00
|
|
|
/** Stack a window above another window, without causing errors.
|
|
|
|
* \param w The window.
|
|
|
|
* \param previous The window which should be below this window.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
stack_window_above(xcb_window_t w, xcb_window_t previous)
|
|
|
|
{
|
|
|
|
if (previous == XCB_NONE)
|
|
|
|
/* This would cause an error from the X server. Also, if we really
|
|
|
|
* changed the stacking order of all windows, they'd all have to redraw
|
|
|
|
* themselves. Doing it like this is better. */
|
|
|
|
return;
|
|
|
|
|
|
|
|
xcb_configure_window(globalconf.connection, w,
|
|
|
|
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
|
|
|
(uint32_t[]) { previous, XCB_STACK_MODE_ABOVE });
|
|
|
|
}
|
|
|
|
|
2009-10-05 20:36:02 +02:00
|
|
|
/** Stack a client above.
|
2015-02-14 18:55:42 +01:00
|
|
|
* \param c The client.
|
2009-10-05 20:36:02 +02:00
|
|
|
* \param previous The previous client on the stack.
|
|
|
|
* \return The next-previous!
|
|
|
|
*/
|
|
|
|
static xcb_window_t
|
|
|
|
stack_client_above(client_t *c, xcb_window_t previous)
|
|
|
|
{
|
2010-07-30 20:54:20 +02:00
|
|
|
stack_window_above(c->frame_window, previous);
|
2009-10-05 20:36:02 +02:00
|
|
|
|
2010-07-30 20:54:20 +02:00
|
|
|
previous = c->frame_window;
|
2009-10-05 20:36:02 +02:00
|
|
|
|
|
|
|
/* stack transient window on top of their parents */
|
|
|
|
foreach(node, globalconf.stack)
|
|
|
|
if((*node)->transient_for == c)
|
|
|
|
previous = stack_client_above(*node, previous);
|
|
|
|
|
|
|
|
return previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Stacking layout layers */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
/** This one is a special layer */
|
|
|
|
WINDOW_LAYER_IGNORE,
|
|
|
|
WINDOW_LAYER_DESKTOP,
|
|
|
|
WINDOW_LAYER_BELOW,
|
|
|
|
WINDOW_LAYER_NORMAL,
|
|
|
|
WINDOW_LAYER_ABOVE,
|
|
|
|
WINDOW_LAYER_FULLSCREEN,
|
|
|
|
WINDOW_LAYER_ONTOP,
|
|
|
|
/** This one only used for counting and is not a real layer */
|
|
|
|
WINDOW_LAYER_COUNT
|
|
|
|
} window_layer_t;
|
|
|
|
|
|
|
|
/** Get the real layer of a client according to its attribute (fullscreen, …)
|
|
|
|
* \param c The client.
|
|
|
|
* \return The real layer.
|
|
|
|
*/
|
|
|
|
static window_layer_t
|
|
|
|
client_layer_translator(client_t *c)
|
|
|
|
{
|
|
|
|
/* first deal with user set attributes */
|
|
|
|
if(c->ontop)
|
|
|
|
return WINDOW_LAYER_ONTOP;
|
2010-07-23 12:22:03 +02:00
|
|
|
/* Fullscreen windows only get their own layer when they have the focus */
|
2010-10-10 14:46:56 +02:00
|
|
|
else if(c->fullscreen && globalconf.focus.client == c)
|
2009-10-05 20:36:02 +02:00
|
|
|
return WINDOW_LAYER_FULLSCREEN;
|
|
|
|
else if(c->above)
|
|
|
|
return WINDOW_LAYER_ABOVE;
|
|
|
|
else if(c->below)
|
|
|
|
return WINDOW_LAYER_BELOW;
|
|
|
|
/* check for transient attr */
|
|
|
|
else if(c->transient_for)
|
|
|
|
return WINDOW_LAYER_IGNORE;
|
|
|
|
|
|
|
|
/* then deal with windows type */
|
|
|
|
switch(c->type)
|
|
|
|
{
|
|
|
|
case WINDOW_TYPE_DESKTOP:
|
|
|
|
return WINDOW_LAYER_DESKTOP;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINDOW_LAYER_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Restack clients.
|
|
|
|
* \todo It might be worth stopping to restack everyone and only stack `c'
|
|
|
|
* relatively to the first matching in the list.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
stack_refresh()
|
|
|
|
{
|
|
|
|
if(!need_stack_refresh)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xcb_window_t next = XCB_NONE;
|
|
|
|
|
2022-12-10 22:17:40 +01:00
|
|
|
foreach(drawin, globalconf.drawins)
|
|
|
|
if ((*drawin)->desktop)
|
|
|
|
{
|
|
|
|
stack_window_above((*drawin)->window, next);
|
|
|
|
next = (*drawin)->window;
|
|
|
|
}
|
|
|
|
|
2009-10-05 20:36:02 +02:00
|
|
|
/* stack desktop windows */
|
|
|
|
for(window_layer_t layer = WINDOW_LAYER_DESKTOP; layer < WINDOW_LAYER_BELOW; layer++)
|
|
|
|
foreach(node, globalconf.stack)
|
|
|
|
if(client_layer_translator(*node) == layer)
|
|
|
|
next = stack_client_above(*node, next);
|
|
|
|
|
2010-10-06 13:35:14 +02:00
|
|
|
/* first stack not ontop drawin window */
|
|
|
|
foreach(drawin, globalconf.drawins)
|
2022-12-10 22:17:40 +01:00
|
|
|
if(!(*drawin)->ontop && !(*drawin)->desktop)
|
2009-10-05 20:36:02 +02:00
|
|
|
{
|
2010-10-06 13:35:14 +02:00
|
|
|
stack_window_above((*drawin)->window, next);
|
|
|
|
next = (*drawin)->window;
|
2009-10-05 20:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* then stack clients */
|
|
|
|
for(window_layer_t layer = WINDOW_LAYER_BELOW; layer < WINDOW_LAYER_COUNT; layer++)
|
|
|
|
foreach(node, globalconf.stack)
|
|
|
|
if(client_layer_translator(*node) == layer)
|
|
|
|
next = stack_client_above(*node, next);
|
|
|
|
|
2010-10-06 13:35:14 +02:00
|
|
|
/* then stack ontop drawin window */
|
|
|
|
foreach(drawin, globalconf.drawins)
|
|
|
|
if((*drawin)->ontop)
|
2009-10-05 20:36:02 +02:00
|
|
|
{
|
2010-10-06 13:35:14 +02:00
|
|
|
stack_window_above((*drawin)->window, next);
|
|
|
|
next = (*drawin)->window;
|
2009-10-05 20:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
need_stack_refresh = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|