2008-06-14 18:12:16 +02:00
|
|
|
/*
|
|
|
|
* systray.c - systray handling
|
|
|
|
*
|
2009-09-14 20:26:33 +02:00
|
|
|
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
|
2008-06-14 18:12:16 +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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "systray.h"
|
2008-06-30 18:55:14 +02:00
|
|
|
#include "common/atoms.h"
|
2016-04-17 13:44:05 +02:00
|
|
|
#include "common/xutil.h"
|
2010-10-06 15:38:44 +02:00
|
|
|
#include "objects/drawin.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "xwindow.h"
|
|
|
|
#include "globalconf.h"
|
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
#include <xcb/xcb_atom.h>
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
#define SYSTEM_TRAY_REQUEST_DOCK 0 /* Begin icon docking */
|
|
|
|
|
2008-09-03 18:03:31 +02:00
|
|
|
/** Initialize systray information in X.
|
|
|
|
*/
|
2008-06-15 10:25:26 +02:00
|
|
|
void
|
2010-08-16 13:47:40 +02:00
|
|
|
systray_init(void)
|
2010-05-21 21:18:12 +02:00
|
|
|
{
|
2014-08-20 11:40:50 +02:00
|
|
|
xcb_intern_atom_cookie_t atom_systray_q;
|
|
|
|
xcb_intern_atom_reply_t *atom_systray_r;
|
|
|
|
char *atom_name;
|
2010-08-16 14:10:58 +02:00
|
|
|
xcb_screen_t *xscreen = globalconf.screen;
|
2010-05-21 21:18:12 +02:00
|
|
|
|
2010-08-16 13:55:12 +02:00
|
|
|
globalconf.systray.window = xcb_generate_id(globalconf.connection);
|
2015-08-12 10:26:27 +02:00
|
|
|
globalconf.systray.background_pixel = xscreen->black_pixel;
|
2010-10-04 09:21:09 +02:00
|
|
|
xcb_create_window(globalconf.connection, xscreen->root_depth,
|
2010-08-16 13:55:12 +02:00
|
|
|
globalconf.systray.window,
|
2010-05-21 21:18:12 +02:00
|
|
|
xscreen->root,
|
|
|
|
-1, -1, 1, 1, 0,
|
2010-10-14 12:54:38 +02:00
|
|
|
XCB_COPY_FROM_PARENT, xscreen->root_visual,
|
2015-10-10 20:34:43 +02:00
|
|
|
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, (const uint32_t [])
|
|
|
|
{ xscreen->black_pixel, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT });
|
2015-11-07 11:48:10 +01:00
|
|
|
xwindow_set_class_instance(globalconf.systray.window);
|
|
|
|
xwindow_set_name_static(globalconf.systray.window, "Awesome systray window");
|
2014-08-20 11:40:50 +02:00
|
|
|
|
|
|
|
atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", globalconf.default_screen);
|
|
|
|
if(!atom_name)
|
|
|
|
fatal("error getting systray atom name");
|
|
|
|
|
|
|
|
atom_systray_q = xcb_intern_atom_unchecked(globalconf.connection, false,
|
|
|
|
a_strlen(atom_name), atom_name);
|
|
|
|
|
|
|
|
p_delete(&atom_name);
|
|
|
|
|
|
|
|
atom_systray_r = xcb_intern_atom_reply(globalconf.connection, atom_systray_q, NULL);
|
|
|
|
if(!atom_systray_r)
|
|
|
|
fatal("error getting systray atom");
|
|
|
|
|
|
|
|
globalconf.systray.atom = atom_systray_r->atom;
|
|
|
|
p_delete(&atom_systray_r);
|
2010-05-21 21:18:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Register systray in X.
|
|
|
|
*/
|
2010-10-06 15:38:44 +02:00
|
|
|
static void
|
2010-08-16 13:47:40 +02:00
|
|
|
systray_register(void)
|
2008-06-15 10:25:26 +02:00
|
|
|
{
|
|
|
|
xcb_client_message_event_t ev;
|
2010-08-16 14:10:58 +02:00
|
|
|
xcb_screen_t *xscreen = globalconf.screen;
|
2008-06-15 10:25:26 +02:00
|
|
|
|
2014-08-20 11:47:47 +02:00
|
|
|
if(globalconf.systray.registered)
|
|
|
|
return;
|
|
|
|
|
|
|
|
globalconf.systray.registered = true;
|
|
|
|
|
2008-06-15 10:25:26 +02:00
|
|
|
/* Fill event */
|
2008-06-24 19:54:54 +02:00
|
|
|
p_clear(&ev, 1);
|
2008-06-15 20:12:49 +02:00
|
|
|
ev.response_type = XCB_CLIENT_MESSAGE;
|
2008-06-24 17:38:44 +02:00
|
|
|
ev.window = xscreen->root;
|
2008-06-15 10:25:26 +02:00
|
|
|
ev.format = 32;
|
2008-06-30 18:55:14 +02:00
|
|
|
ev.type = MANAGER;
|
2017-04-15 12:05:42 +02:00
|
|
|
ev.data.data32[0] = globalconf.timestamp;
|
2014-08-20 11:40:50 +02:00
|
|
|
ev.data.data32[1] = globalconf.systray.atom;
|
2010-08-16 13:55:12 +02:00
|
|
|
ev.data.data32[2] = globalconf.systray.window;
|
2008-06-15 10:25:26 +02:00
|
|
|
ev.data.data32[3] = ev.data.data32[4] = 0;
|
|
|
|
|
|
|
|
xcb_set_selection_owner(globalconf.connection,
|
2010-08-16 13:55:12 +02:00
|
|
|
globalconf.systray.window,
|
2014-08-20 11:40:50 +02:00
|
|
|
globalconf.systray.atom,
|
2017-04-15 12:05:42 +02:00
|
|
|
globalconf.timestamp);
|
2008-06-15 11:22:34 +02:00
|
|
|
|
2008-06-24 19:54:54 +02:00
|
|
|
xcb_send_event(globalconf.connection, false, xscreen->root, 0xFFFFFF, (char *) &ev);
|
2008-06-15 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
2008-09-03 18:03:31 +02:00
|
|
|
/** Remove systray information in X.
|
|
|
|
*/
|
|
|
|
void
|
2010-08-16 13:47:40 +02:00
|
|
|
systray_cleanup(void)
|
2008-09-03 18:03:31 +02:00
|
|
|
{
|
2014-08-20 11:47:47 +02:00
|
|
|
if(!globalconf.systray.registered)
|
|
|
|
return;
|
|
|
|
|
|
|
|
globalconf.systray.registered = false;
|
|
|
|
|
2008-09-03 18:03:31 +02:00
|
|
|
xcb_set_selection_owner(globalconf.connection,
|
|
|
|
XCB_NONE,
|
2014-08-20 11:40:50 +02:00
|
|
|
globalconf.systray.atom,
|
2017-04-15 12:05:42 +02:00
|
|
|
globalconf.timestamp);
|
2008-09-03 18:03:31 +02:00
|
|
|
|
2010-10-06 15:38:44 +02:00
|
|
|
xcb_unmap_window(globalconf.connection,
|
|
|
|
globalconf.systray.window);
|
2008-09-03 18:03:31 +02:00
|
|
|
}
|
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
/** Handle a systray request.
|
|
|
|
* \param embed_win The window to embed.
|
2009-07-27 06:20:00 +02:00
|
|
|
* \return 0 on no error.
|
2008-06-14 18:12:16 +02:00
|
|
|
*/
|
2008-06-30 13:06:23 +02:00
|
|
|
int
|
2016-05-29 14:29:23 +02:00
|
|
|
systray_request_handle(xcb_window_t embed_win)
|
2008-06-14 18:12:16 +02:00
|
|
|
{
|
2008-12-01 16:43:44 +01:00
|
|
|
xembed_window_t em;
|
2008-08-12 15:29:01 +02:00
|
|
|
xcb_get_property_cookie_t em_cookie;
|
2008-06-14 18:12:16 +02:00
|
|
|
const uint32_t select_input_val[] =
|
|
|
|
{
|
|
|
|
XCB_EVENT_MASK_STRUCTURE_NOTIFY
|
|
|
|
| XCB_EVENT_MASK_PROPERTY_CHANGE
|
|
|
|
| XCB_EVENT_MASK_ENTER_WINDOW
|
|
|
|
};
|
|
|
|
|
2008-06-29 13:38:02 +02:00
|
|
|
/* check if not already trayed */
|
2008-12-01 16:43:44 +01:00
|
|
|
if(xembed_getbywin(&globalconf.embedded, embed_win))
|
2008-06-30 13:06:23 +02:00
|
|
|
return -1;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-08-12 15:29:01 +02:00
|
|
|
p_clear(&em_cookie, 1);
|
|
|
|
|
2016-05-29 14:29:23 +02:00
|
|
|
em_cookie = xembed_info_get_unchecked(globalconf.connection, embed_win);
|
2008-08-12 15:29:01 +02:00
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
xcb_change_window_attributes(globalconf.connection, embed_win, XCB_CW_EVENT_MASK,
|
|
|
|
select_input_val);
|
|
|
|
|
2010-07-14 17:26:55 +02:00
|
|
|
/* we grab the window, but also make sure it's automatically reparented back
|
|
|
|
* to the root window if we should die.
|
|
|
|
*/
|
|
|
|
xcb_change_save_set(globalconf.connection, XCB_SET_MODE_INSERT, embed_win);
|
2008-09-01 17:54:53 +02:00
|
|
|
xcb_reparent_window(globalconf.connection, embed_win,
|
2010-08-16 13:55:12 +02:00
|
|
|
globalconf.systray.window,
|
2008-09-01 17:54:53 +02:00
|
|
|
0, 0);
|
|
|
|
|
2008-12-01 16:43:44 +01:00
|
|
|
em.win = embed_win;
|
2008-08-12 15:29:01 +02:00
|
|
|
|
2016-05-29 14:31:22 +02:00
|
|
|
if (!xembed_info_get_reply(globalconf.connection, em_cookie, &em.info)) {
|
|
|
|
/* Set some sane defaults */
|
|
|
|
em.info.version = XEMBED_VERSION;
|
|
|
|
em.info.flags = XEMBED_MAPPED;
|
|
|
|
}
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-12-01 16:43:44 +01:00
|
|
|
xembed_embedded_notify(globalconf.connection, em.win,
|
2017-04-15 12:04:57 +02:00
|
|
|
globalconf.timestamp, globalconf.systray.window,
|
2008-12-01 16:43:44 +01:00
|
|
|
MIN(XEMBED_VERSION, em.info.version));
|
|
|
|
|
|
|
|
xembed_window_array_append(&globalconf.embedded, em);
|
2010-10-06 15:38:44 +02:00
|
|
|
luaA_systray_invalidate();
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Handle systray message.
|
|
|
|
* \param ev The event.
|
|
|
|
* \return 0 on no error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
systray_process_client_message(xcb_client_message_event_t *ev)
|
|
|
|
{
|
2010-08-16 13:47:40 +02:00
|
|
|
int ret = 0;
|
2008-06-14 18:12:16 +02:00
|
|
|
xcb_get_geometry_cookie_t geom_c;
|
|
|
|
xcb_get_geometry_reply_t *geom_r;
|
|
|
|
|
|
|
|
switch(ev->data.data32[1])
|
|
|
|
{
|
|
|
|
case SYSTEM_TRAY_REQUEST_DOCK:
|
2008-06-21 12:56:51 +02:00
|
|
|
geom_c = xcb_get_geometry_unchecked(globalconf.connection, ev->window);
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
if(!(geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2010-08-16 14:10:58 +02:00
|
|
|
if(globalconf.screen->root == geom_r->root)
|
2016-05-29 14:29:23 +02:00
|
|
|
ret = systray_request_handle(ev->data.data32[2]);
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
p_delete(&geom_r);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-29 13:38:02 +02:00
|
|
|
|
|
|
|
return ret;
|
2008-06-14 18:12:16 +02:00
|
|
|
}
|
|
|
|
|
2008-06-30 13:06:23 +02:00
|
|
|
/** Check if a window is a KDE tray.
|
|
|
|
* \param w The window to check.
|
|
|
|
* \return True if it is, false otherwise.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
systray_iskdedockapp(xcb_window_t w)
|
|
|
|
{
|
|
|
|
xcb_get_property_cookie_t kde_check_q;
|
|
|
|
xcb_get_property_reply_t *kde_check;
|
|
|
|
bool ret;
|
|
|
|
|
2009-08-30 07:26:19 +02:00
|
|
|
/* Check if that is a KDE tray because it does not respect fdo standards,
|
2008-06-30 13:06:23 +02:00
|
|
|
* thanks KDE. */
|
|
|
|
kde_check_q = xcb_get_property_unchecked(globalconf.connection, false, w,
|
2008-06-30 18:55:14 +02:00
|
|
|
_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR,
|
2010-08-08 18:31:07 +02:00
|
|
|
XCB_ATOM_WINDOW, 0, 1);
|
2008-06-30 13:06:23 +02:00
|
|
|
|
|
|
|
kde_check = xcb_get_property_reply(globalconf.connection, kde_check_q, NULL);
|
|
|
|
|
|
|
|
/* it's a KDE systray ?*/
|
|
|
|
ret = (kde_check && kde_check->value_len);
|
|
|
|
|
|
|
|
p_delete(&kde_check);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
/** Handle xembed client message.
|
|
|
|
* \param ev The event.
|
|
|
|
* \return 0 on no error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xembed_process_client_message(xcb_client_message_event_t *ev)
|
|
|
|
{
|
|
|
|
switch(ev->data.data32[1])
|
|
|
|
{
|
|
|
|
case XEMBED_REQUEST_FOCUS:
|
2017-04-15 12:04:57 +02:00
|
|
|
xembed_focus_in(globalconf.connection, ev->window,
|
|
|
|
globalconf.timestamp, XEMBED_FOCUS_CURRENT);
|
2008-06-14 18:12:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-14 14:30:22 +02:00
|
|
|
static int
|
|
|
|
systray_num_visible_entries(void)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
foreach(em, globalconf.embedded)
|
|
|
|
if (em->info.flags & XEMBED_MAPPED)
|
|
|
|
result++;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-10-06 15:38:44 +02:00
|
|
|
/** Inform lua that the systray needs to be updated.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
luaA_systray_invalidate(void)
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
signal_object_emit(L, &global_signals, "systray::update", 0);
|
2016-01-15 17:21:26 +01:00
|
|
|
|
|
|
|
/* Unmap now if the systray became empty */
|
2016-05-14 14:30:22 +02:00
|
|
|
if(systray_num_visible_entries() == 0)
|
2016-01-15 17:21:26 +01:00
|
|
|
xcb_unmap_window(globalconf.connection, globalconf.systray.window);
|
2010-10-06 15:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-12 10:26:27 +02:00
|
|
|
systray_update(int base_size, bool horizontal, bool reverse, int spacing, bool force_redraw)
|
2010-10-06 15:38:44 +02:00
|
|
|
{
|
|
|
|
if(base_size <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Give the systray window the correct size */
|
2016-05-14 14:30:22 +02:00
|
|
|
int num_entries = systray_num_visible_entries();
|
2010-10-06 15:38:44 +02:00
|
|
|
uint32_t config_vals[4] = { base_size, base_size, 0, 0 };
|
|
|
|
if(horizontal)
|
2016-05-14 14:30:22 +02:00
|
|
|
config_vals[0] = base_size * num_entries + spacing * (num_entries - 1);
|
2010-10-06 15:38:44 +02:00
|
|
|
else
|
2016-05-14 14:30:22 +02:00
|
|
|
config_vals[1] = base_size * num_entries + spacing * (num_entries - 1);
|
2010-10-06 15:38:44 +02:00
|
|
|
xcb_configure_window(globalconf.connection,
|
|
|
|
globalconf.systray.window,
|
|
|
|
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
|
|
|
config_vals);
|
|
|
|
|
|
|
|
/* Now resize each embedded window */
|
|
|
|
config_vals[0] = config_vals[1] = 0;
|
|
|
|
config_vals[2] = config_vals[3] = base_size;
|
|
|
|
for(int i = 0; i < globalconf.embedded.len; i++)
|
|
|
|
{
|
2014-04-02 15:25:03 +02:00
|
|
|
xembed_window_t *em;
|
|
|
|
|
|
|
|
if(reverse)
|
|
|
|
em = &globalconf.embedded.tab[(globalconf.embedded.len - i - 1)];
|
|
|
|
else
|
|
|
|
em = &globalconf.embedded.tab[i];
|
|
|
|
|
2016-05-14 14:30:22 +02:00
|
|
|
if (!(em->info.flags & XEMBED_MAPPED))
|
|
|
|
{
|
|
|
|
xcb_unmap_window(globalconf.connection, em->win);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-10-06 15:38:44 +02:00
|
|
|
xcb_configure_window(globalconf.connection, em->win,
|
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
|
|
|
config_vals);
|
|
|
|
xcb_map_window(globalconf.connection, em->win);
|
2015-08-12 10:26:27 +02:00
|
|
|
if (force_redraw)
|
|
|
|
xcb_clear_area(globalconf.connection, 1, em->win, 0, 0, 0, 0);
|
2010-10-06 15:38:44 +02:00
|
|
|
if(horizontal)
|
2014-05-10 06:08:42 +02:00
|
|
|
config_vals[0] += base_size + spacing;
|
2010-10-06 15:38:44 +02:00
|
|
|
else
|
2014-05-10 06:08:42 +02:00
|
|
|
config_vals[1] += base_size + spacing;
|
2010-10-06 15:38:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Update the systray
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam The drawin to display the systray in.
|
|
|
|
* \lparam x X position for the systray.
|
|
|
|
* \lparam y Y position for the systray.
|
|
|
|
* \lparam base_size The size (width and height) each systray item gets.
|
2014-05-11 17:21:57 +02:00
|
|
|
* \lparam horiz If true, the systray is horizontal, else vertical.
|
|
|
|
* \lparam bg Color of the systray background.
|
|
|
|
* \lparam revers If true, the systray icon order will be reversed, else default.
|
|
|
|
* \lparam spacing The size of the spacing between icons.
|
2010-10-06 15:38:44 +02:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_systray(lua_State *L)
|
|
|
|
{
|
2014-08-20 11:47:47 +02:00
|
|
|
systray_register();
|
2014-08-18 07:32:11 +02:00
|
|
|
|
Partly fix removal of systray from a wibox
This commit changes the systray widget, wibox.drawable and the C code to
fix the following bug: When the systray widget is removed from a
drawable without being moved somewhere else, the systray stayed visible.
This was because the systray is not drawn by awesome, but only placed.
When the widget is no longer "drawn", it stays wherever it was placed
last.
This change works by detecting the situation when the systray is
removed. Then, the C code is specifically told to remove the systray
window from the drawable.
Note that this is only a partial fix. This change works correctly when
the widget is removed completely, because it is no longer placed by its
parent widget. However, for example, when you do
wibox.widget.systray().visible = false, the effect is just that the
systray widget gets size 0x0. This is not really visible, but as far as
this change is concerned, the widget is still part of the drawable.
Signed-off-by: Uli Schlachter <psychon@znc.in>
2017-03-11 18:14:38 +01:00
|
|
|
if(lua_gettop(L) == 1)
|
|
|
|
luaA_drawin_systray_kickout(L);
|
|
|
|
|
|
|
|
if(lua_gettop(L) > 1)
|
2010-10-06 15:38:44 +02:00
|
|
|
{
|
2010-10-17 09:24:59 +02:00
|
|
|
size_t bg_len;
|
2010-10-06 15:38:44 +02:00
|
|
|
drawin_t *w = luaA_checkudata(L, 1, &drawin_class);
|
2016-04-18 07:15:15 +02:00
|
|
|
int x = round(luaA_checknumber_range(L, 2, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
|
|
|
int y = round(luaA_checknumber_range(L, 3, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
|
|
|
int base_size = ceil(luaA_checknumber_range(L, 4, MIN_X11_SIZE, MAX_X11_SIZE));
|
2010-10-06 15:38:44 +02:00
|
|
|
bool horiz = lua_toboolean(L, 5);
|
2010-10-17 09:24:59 +02:00
|
|
|
const char *bg = luaL_checklstring(L, 6, &bg_len);
|
2014-04-02 15:25:03 +02:00
|
|
|
bool revers = lua_toboolean(L, 7);
|
2016-04-18 07:15:15 +02:00
|
|
|
int spacing = ceil(luaA_checknumber_range(L, 8, 0, MAX_X11_COORDINATE));
|
2010-10-17 09:24:59 +02:00
|
|
|
color_t bg_color;
|
2015-08-12 10:26:27 +02:00
|
|
|
bool force_redraw = false;
|
2010-10-17 09:24:59 +02:00
|
|
|
|
Make alpha work on window borders
Up to now, we always asked the X11 server for color allocation ("which
pixel value corresponds to (r,g,b)?", an AllocCollor request).
This commit adds direct support for TrueColor and DirectColor visuals.
In such a visual, the X11 server gives tells us where the red, green,
and blue color components are in a pixel value and we can then just
directly compute the pixel value.
Additionally, this commit adds code that assumes that in a depth=32
visual, the remaining values (after handling red, green, blue) is the
alpha channel for colors. Thus, this adds support for transparent client
borders.
This commit also touches code for the systray. However, the systray must
always use the X11 server's default visual and that one always(?) has
depth=24, i.e. does not support an alpha channel. Thus, the systray
background still cannot be transparent.
Also, in theory this commit should support visuals where some color
component does not have 8 bits, for example RGB565. However, this is
just theoretic and I have no idea how to actually test this (without
jumping through too many hoops).
Fixes: https://github.com/awesomeWM/awesome/issues/162
Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-03-02 14:16:51 +01:00
|
|
|
if(color_init_reply(color_init_unchecked(&bg_color, bg, bg_len, globalconf.default_visual))
|
2015-08-12 10:26:27 +02:00
|
|
|
&& globalconf.systray.background_pixel != bg_color.pixel)
|
2010-10-17 09:24:59 +02:00
|
|
|
{
|
|
|
|
uint32_t config_back[] = { bg_color.pixel };
|
2015-08-12 10:26:27 +02:00
|
|
|
globalconf.systray.background_pixel = bg_color.pixel;
|
2010-10-17 09:24:59 +02:00
|
|
|
xcb_change_window_attributes(globalconf.connection,
|
|
|
|
globalconf.systray.window,
|
|
|
|
XCB_CW_BACK_PIXEL, config_back);
|
2015-08-12 10:26:27 +02:00
|
|
|
xcb_clear_area(globalconf.connection, 1, globalconf.systray.window, 0, 0, 0, 0);
|
|
|
|
force_redraw = true;
|
2010-10-17 09:24:59 +02:00
|
|
|
}
|
2010-10-06 15:38:44 +02:00
|
|
|
|
2010-10-07 11:31:51 +02:00
|
|
|
if(globalconf.systray.parent != w)
|
2010-10-06 15:38:44 +02:00
|
|
|
xcb_reparent_window(globalconf.connection,
|
|
|
|
globalconf.systray.window,
|
|
|
|
w->window,
|
|
|
|
x, y);
|
2010-10-07 11:31:51 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
uint32_t config_vals[2] = { x, y };
|
|
|
|
xcb_configure_window(globalconf.connection,
|
|
|
|
globalconf.systray.window,
|
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
|
|
|
config_vals);
|
|
|
|
}
|
|
|
|
|
|
|
|
globalconf.systray.parent = w;
|
|
|
|
|
2016-05-14 14:30:22 +02:00
|
|
|
if(systray_num_visible_entries() != 0)
|
2010-10-07 11:31:51 +02:00
|
|
|
{
|
2015-08-12 10:26:27 +02:00
|
|
|
systray_update(base_size, horiz, revers, spacing, force_redraw);
|
2010-10-06 15:38:44 +02:00
|
|
|
xcb_map_window(globalconf.connection,
|
|
|
|
globalconf.systray.window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 14:30:22 +02:00
|
|
|
lua_pushinteger(L, systray_num_visible_entries());
|
2010-10-06 15:38:44 +02:00
|
|
|
luaA_object_push(L, globalconf.systray.parent);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|