2008-03-04 20:39:21 +01:00
|
|
|
/*
|
|
|
|
* common/xutil.c - X-related useful functions
|
|
|
|
*
|
2009-04-26 12:34:13 +02:00
|
|
|
* Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
|
2008-03-04 20:39:21 +01: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "common/xutil.h"
|
|
|
|
|
2009-04-28 18:17:16 +02:00
|
|
|
/* XCB doesn't provide keysyms definition */
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
#include <xcb/xcb.h>
|
2008-09-09 16:14:36 +02:00
|
|
|
#include <xcb/xcb_icccm.h>
|
2008-03-04 20:39:21 +01:00
|
|
|
|
2009-04-15 14:03:17 +02:00
|
|
|
uint16_t
|
2010-09-02 19:12:21 +02:00
|
|
|
xutil_key_mask_fromstr(const char *keyname)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2011-11-17 16:38:39 +01:00
|
|
|
if (A_STREQ(keyname, "Shift"))
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_MOD_MASK_SHIFT;
|
2011-11-17 16:38:39 +01:00
|
|
|
if (A_STREQ(keyname, "Lock"))
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_MOD_MASK_LOCK;
|
2011-11-17 16:38:39 +01:00
|
|
|
if (A_STREQ(keyname, "Ctrl") || A_STREQ(keyname, "Control"))
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_MOD_MASK_CONTROL;
|
2011-11-17 16:38:39 +01:00
|
|
|
if (A_STREQ(keyname, "Mod1"))
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_MOD_MASK_1;
|
2011-11-17 16:38:39 +01:00
|
|
|
if(A_STREQ(keyname, "Mod2"))
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_MOD_MASK_2;
|
2011-11-17 16:38:39 +01:00
|
|
|
if(A_STREQ(keyname, "Mod3"))
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_MOD_MASK_3;
|
2011-11-17 16:38:39 +01:00
|
|
|
if(A_STREQ(keyname, "Mod4"))
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_MOD_MASK_4;
|
2011-11-17 16:38:39 +01:00
|
|
|
if(A_STREQ(keyname, "Mod5"))
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_MOD_MASK_5;
|
2011-11-17 16:38:39 +01:00
|
|
|
if(A_STREQ(keyname, "Any"))
|
2009-04-15 13:59:22 +02:00
|
|
|
/* this is misnamed but correct */
|
2010-09-02 19:12:21 +02:00
|
|
|
return XCB_BUTTON_MASK_ANY;
|
|
|
|
return XCB_NO_SYMBOL;
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
2009-04-25 15:59:22 +02:00
|
|
|
void
|
|
|
|
xutil_key_mask_tostr(uint16_t mask, const char **name, size_t *len)
|
|
|
|
{
|
|
|
|
switch(mask)
|
|
|
|
{
|
|
|
|
#define SET_RESULT(res) \
|
|
|
|
*name = #res; \
|
|
|
|
*len = sizeof(#res) - 1; \
|
|
|
|
return;
|
|
|
|
case XCB_MOD_MASK_SHIFT: SET_RESULT(Shift)
|
|
|
|
case XCB_MOD_MASK_LOCK: SET_RESULT(Lock)
|
|
|
|
case XCB_MOD_MASK_CONTROL: SET_RESULT(Control)
|
|
|
|
case XCB_MOD_MASK_1: SET_RESULT(Mod1)
|
|
|
|
case XCB_MOD_MASK_2: SET_RESULT(Mod2)
|
|
|
|
case XCB_MOD_MASK_3: SET_RESULT(Mod3)
|
|
|
|
case XCB_MOD_MASK_4: SET_RESULT(Mod4)
|
|
|
|
case XCB_MOD_MASK_5: SET_RESULT(Mod5)
|
|
|
|
case XCB_BUTTON_MASK_ANY: SET_RESULT(Any)
|
|
|
|
default: SET_RESULT(Unknown)
|
|
|
|
#undef SET_RESULT
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|