2009-01-02 20:11:21 +01:00
|
|
|
/*
|
|
|
|
* selection.c - Selection handling
|
|
|
|
*
|
|
|
|
* Copyright © 2009 Julien Danjou <julien@danjou.info>
|
|
|
|
* Copyright © 2009 Gregor Best <farhaven@googlemail.com>
|
|
|
|
*
|
|
|
|
* 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 <xcb/xcb_atom.h>
|
|
|
|
|
2009-01-06 17:02:08 +01:00
|
|
|
#include "selection.h"
|
2009-01-02 20:11:21 +01:00
|
|
|
#include "event.h"
|
|
|
|
#include "common/atoms.h"
|
2009-04-17 16:52:25 +02:00
|
|
|
#include "common/xutil.h"
|
2009-01-02 20:11:21 +01:00
|
|
|
|
|
|
|
static xcb_window_t selection_window = XCB_NONE;
|
|
|
|
|
|
|
|
/** Get the current X selection buffer.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lreturn A string with the current X selection buffer.
|
|
|
|
*/
|
2009-01-06 17:02:08 +01:00
|
|
|
int
|
2009-01-02 20:11:21 +01:00
|
|
|
luaA_selection_get(lua_State *L)
|
|
|
|
{
|
|
|
|
if(selection_window == XCB_NONE)
|
|
|
|
{
|
|
|
|
xcb_screen_t *screen = xutil_screen_get(globalconf.connection, globalconf.default_screen);
|
|
|
|
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
|
|
|
|
uint32_t values[] = { screen->black_pixel, 1, XCB_EVENT_MASK_PROPERTY_CHANGE };
|
|
|
|
|
|
|
|
selection_window = xcb_generate_id(globalconf.connection);
|
|
|
|
|
|
|
|
xcb_create_window(globalconf.connection, screen->root_depth, selection_window, screen->root,
|
|
|
|
0, 0, 1, 1, 0, XCB_COPY_FROM_PARENT, screen->root_visual,
|
|
|
|
mask, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_convert_selection(globalconf.connection, selection_window,
|
2010-08-12 14:52:23 +02:00
|
|
|
XCB_ATOM_PRIMARY, UTF8_STRING, XSEL_DATA, globalconf.timestamp);
|
2009-01-02 20:11:21 +01:00
|
|
|
xcb_flush(globalconf.connection);
|
|
|
|
|
|
|
|
xcb_generic_event_t *event;
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
event = xcb_wait_for_event(globalconf.connection);
|
|
|
|
|
|
|
|
if(!event)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(XCB_EVENT_RESPONSE_TYPE(event) != XCB_SELECTION_NOTIFY)
|
|
|
|
{
|
|
|
|
/* \todo Eventually, this may be rewritten with adding a static
|
|
|
|
* buffer, then a event handler for XCB_SELECTION_NOTIFY, then call
|
|
|
|
* xcb_event_poll_for_event_loop() and awesome_refresh(),
|
|
|
|
* then check if some static buffer has been filled with data.
|
|
|
|
* If yes, that'd be the xsel data, otherwise, re-loop.
|
2009-08-30 07:26:19 +02:00
|
|
|
* Anyway that's still brakes the socket or D-Bus, so maybe using
|
2009-01-02 20:11:21 +01:00
|
|
|
* ev_loop() would be even better.
|
|
|
|
*/
|
2010-08-08 17:35:48 +02:00
|
|
|
event_handle(event);
|
2009-01-02 20:11:21 +01:00
|
|
|
p_delete(&event);
|
2009-04-10 17:39:11 +02:00
|
|
|
awesome_refresh();
|
2009-01-02 20:11:21 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_selection_notify_event_t *event_notify =
|
|
|
|
(xcb_selection_notify_event_t *) event;
|
|
|
|
|
2010-08-08 18:31:07 +02:00
|
|
|
if(event_notify->selection == XCB_ATOM_PRIMARY
|
2009-01-02 20:11:21 +01:00
|
|
|
&& event_notify->property != XCB_NONE)
|
|
|
|
{
|
2011-04-27 08:44:35 +02:00
|
|
|
xcb_icccm_get_text_property_reply_t prop;
|
2009-01-02 20:11:21 +01:00
|
|
|
xcb_get_property_cookie_t cookie =
|
2011-04-27 08:44:35 +02:00
|
|
|
xcb_icccm_get_text_property(globalconf.connection,
|
|
|
|
event_notify->requestor,
|
|
|
|
event_notify->property);
|
2009-01-02 20:11:21 +01:00
|
|
|
|
2011-04-27 08:44:35 +02:00
|
|
|
if(xcb_icccm_get_text_property_reply(globalconf.connection,
|
|
|
|
cookie, &prop, NULL))
|
2009-01-02 20:11:21 +01:00
|
|
|
{
|
|
|
|
lua_pushlstring(L, prop.name, prop.name_len);
|
|
|
|
|
2011-04-27 08:44:35 +02:00
|
|
|
xcb_icccm_get_text_property_reply_wipe(&prop);
|
2009-01-02 20:11:21 +01:00
|
|
|
|
|
|
|
xcb_delete_property(globalconf.connection,
|
|
|
|
event_notify->requestor,
|
|
|
|
event_notify->property);
|
|
|
|
|
|
|
|
p_delete(&event);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p_delete(&event);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-21 16:44:30 +02:00
|
|
|
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|