add some globals to modify the default scripting behavior
This commit is contained in:
parent
103372b02f
commit
f7e3eb5729
6 changed files with 59 additions and 174 deletions
|
@ -26,7 +26,8 @@ def def_press_model(action, win, type, modifiers, button, xroot, yroot, time):
|
||||||
type == Type_MaximizeButton or
|
type == Type_MaximizeButton or
|
||||||
type == Type_CloseButton):
|
type == Type_CloseButton):
|
||||||
return
|
return
|
||||||
OBClient_focus(client)
|
if click_focus != 0:
|
||||||
|
OBClient_focus(client)
|
||||||
print "OBClient_raise(client)"
|
print "OBClient_raise(client)"
|
||||||
|
|
||||||
def def_click_root(action, win, type, modifiers, button, time):
|
def def_click_root(action, win, type, modifiers, button, time):
|
||||||
|
@ -52,7 +53,7 @@ def def_doubleclick_client(action, win, type, modifiers, button, time):
|
||||||
print "OBClient_toggleshade(client)"
|
print "OBClient_toggleshade(client)"
|
||||||
|
|
||||||
|
|
||||||
#preregister(Action_ButtonPress, def_press_model)
|
preregister(Action_ButtonPress, def_press_model)
|
||||||
register(Action_Click, def_click_client)
|
register(Action_Click, def_click_client)
|
||||||
register(Action_Click, def_click_root)
|
register(Action_Click, def_click_root)
|
||||||
register(Action_DoubleClick, def_doubleclick_client)
|
register(Action_DoubleClick, def_doubleclick_client)
|
||||||
|
|
|
@ -9,24 +9,11 @@ def def_motion_press(action, win, type, modifiers, button, xroot, yroot, time):
|
||||||
newi.append(new_Rect(OBClient_area(client)))
|
newi.append(new_Rect(OBClient_area(client)))
|
||||||
posqueue.append(newi)
|
posqueue.append(newi)
|
||||||
|
|
||||||
# ButtonPressAction *a = _posqueue[BUTTONS - 1];
|
|
||||||
# for (int i=BUTTONS-1; i>0;)
|
|
||||||
# _posqueue[i] = _posqueue[--i];
|
|
||||||
# _posqueue[0] = a;
|
|
||||||
# a->button = e.button;
|
|
||||||
# a->pos.setPoint(e.x_root, e.y_root);
|
|
||||||
|
|
||||||
# OBClient *c = Openbox::instance->findClient(e.window);
|
|
||||||
# // if it's not defined, they should have clicked on the root window, so this
|
|
||||||
# // area would be meaningless anyways
|
|
||||||
# if (c) a->clientarea = c->area();
|
|
||||||
|
|
||||||
def def_motion_release(action, win, type, modifiers, button, xroot, yroot,
|
def def_motion_release(action, win, type, modifiers, button, xroot, yroot,
|
||||||
time):
|
time):
|
||||||
global posqueue
|
global posqueue
|
||||||
for i in posqueue:
|
for i in posqueue:
|
||||||
if i[0] == button:
|
if i[0] == button:
|
||||||
print "hi"
|
|
||||||
client = Openbox_findClient(openbox, win)
|
client = Openbox_findClient(openbox, win)
|
||||||
if client:
|
if client:
|
||||||
delete_Rect(i[3])
|
delete_Rect(i[3])
|
||||||
|
@ -53,7 +40,7 @@ def def_motion(action, win, type, modifiers, xroot, yroot, time):
|
||||||
if not client: return
|
if not client: return
|
||||||
|
|
||||||
if (type == Type_Titlebar) or (type == Type_Label):
|
if (type == Type_Titlebar) or (type == Type_Label):
|
||||||
def_do_move(client, xroot, yroot)
|
def_do_motion(client, xroot, yroot)
|
||||||
elif type == Type_LeftGrip:
|
elif type == Type_LeftGrip:
|
||||||
def_do_resize(client, xroot, yroot, OBClient_TopRight)
|
def_do_resize(client, xroot, yroot, OBClient_TopRight)
|
||||||
elif type == Type_RightGrip:
|
elif type == Type_RightGrip:
|
||||||
|
@ -62,15 +49,18 @@ def def_motion(action, win, type, modifiers, xroot, yroot, time):
|
||||||
def def_enter(action, win, type, modifiers):
|
def def_enter(action, win, type, modifiers):
|
||||||
client = Openbox_findClient(openbox, win)
|
client = Openbox_findClient(openbox, win)
|
||||||
if not client: return
|
if not client: return
|
||||||
OBClient_focus(client)
|
if enter_focus != 0:
|
||||||
|
OBClient_focus(client)
|
||||||
|
|
||||||
def def_leave(action, win, type, modifiers):
|
def def_leave(action, win, type, modifiers):
|
||||||
client = Openbox_findClient(openbox, win)
|
client = Openbox_findClient(openbox, win)
|
||||||
if not client: return
|
if not client: return
|
||||||
|
if leave_unfocus != 0:
|
||||||
|
OBClient_unfocus(client)
|
||||||
|
|
||||||
|
|
||||||
register(Action_EnterWindow, def_enter)
|
register(Action_EnterWindow, def_enter)
|
||||||
#register(Action_LeaveWindow, def_leave)
|
register(Action_LeaveWindow, def_leave)
|
||||||
|
|
||||||
register(Action_ButtonPress, def_motion_press)
|
register(Action_ButtonPress, def_motion_press)
|
||||||
register(Action_ButtonRelease, def_motion_release)
|
register(Action_ButtonRelease, def_motion_release)
|
||||||
|
|
|
@ -6,4 +6,19 @@ screen = []
|
||||||
for i in range(Openbox_screenCount(openbox)):
|
for i in range(Openbox_screenCount(openbox)):
|
||||||
screen.append(Openbox_screen(openbox, i))
|
screen.append(Openbox_screen(openbox, i))
|
||||||
|
|
||||||
|
# client_buttons - a list of the modifier(s) and buttons which are grabbed on
|
||||||
|
# client windows (for interactive move/resize, etc)
|
||||||
|
# examples: "A-2", "C-A-2", "W-1"
|
||||||
|
client_buttons = ["A-1", "A-2", "A-3"]
|
||||||
|
|
||||||
|
# click_focus - true if clicking in a client will cause it to focus in the
|
||||||
|
# default hook functions
|
||||||
|
click_focus = 0
|
||||||
|
# enter_focus - true if entering a client window will cause it to focus in the
|
||||||
|
# default hook functions
|
||||||
|
enter_focus = 1
|
||||||
|
# leave_unfocus - true if leaving a client window will cause it to unfocus in
|
||||||
|
# the default hook functions
|
||||||
|
leave_unfocus = 1
|
||||||
|
|
||||||
print "Loaded globals.py"
|
print "Loaded globals.py"
|
||||||
|
|
152
src/bindings.cc
152
src/bindings.cc
|
@ -68,8 +68,7 @@ static bool modvalue(const std::string &mod, unsigned int *val)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OBBindings::translate(const std::string &str, Binding &b,
|
bool OBBindings::translate(const std::string &str, Binding &b) const
|
||||||
bool askey) const
|
|
||||||
{
|
{
|
||||||
// parse out the base key name
|
// parse out the base key name
|
||||||
std::string::size_type keybegin = str.find_last_of('-');
|
std::string::size_type keybegin = str.find_last_of('-');
|
||||||
|
@ -93,22 +92,14 @@ bool OBBindings::translate(const std::string &str, Binding &b,
|
||||||
|
|
||||||
// set the binding
|
// set the binding
|
||||||
b.modifiers = modval;
|
b.modifiers = modval;
|
||||||
if (askey) {
|
KeySym sym = XStringToKeysym(const_cast<char *>(key.c_str()));
|
||||||
KeySym sym = XStringToKeysym(const_cast<char *>(key.c_str()));
|
if (sym == NoSymbol) {
|
||||||
if (sym == NoSymbol) {
|
printf(_("Invalid Key name in key binding: %s\n"), key.c_str());
|
||||||
printf(_("Invalid Key name in key binding: %s\n"), key.c_str());
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!(b.key = XKeysymToKeycode(otk::OBDisplay::display, sym)))
|
|
||||||
printf(_("No valid keycode for Key in key binding: %s\n"), key.c_str());
|
|
||||||
return b.key != 0;
|
|
||||||
} else {
|
|
||||||
if (!buttonvalue(key, &b.key)) {
|
|
||||||
printf(_("Invalid Button name in mouse binding: %s\n"), key.c_str());
|
|
||||||
return false;
|
|
||||||
} else
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (!(b.key = XKeysymToKeycode(otk::OBDisplay::display, sym)))
|
||||||
|
printf(_("No valid keycode for Key in key binding: %s\n"), key.c_str());
|
||||||
|
return b.key != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroytree(BindingTree *tree)
|
static void destroytree(BindingTree *tree)
|
||||||
|
@ -143,7 +134,7 @@ BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) const
|
||||||
|
|
||||||
|
|
||||||
OBBindings::OBBindings()
|
OBBindings::OBBindings()
|
||||||
: _curpos(&_keytree), _mousetree(0), _resetkey(0,0)
|
: _curpos(&_keytree), _resetkey(0,0)
|
||||||
{
|
{
|
||||||
setResetKey("C-g"); // set the default reset key
|
setResetKey("C-g"); // set the default reset key
|
||||||
}
|
}
|
||||||
|
@ -151,53 +142,11 @@ OBBindings::OBBindings()
|
||||||
|
|
||||||
OBBindings::~OBBindings()
|
OBBindings::~OBBindings()
|
||||||
{
|
{
|
||||||
grabMouseOnAll(false); // ungrab everything
|
|
||||||
grabKeys(false);
|
grabKeys(false);
|
||||||
remove_all();
|
remove_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool OBBindings::add_mouse(const std::string &button, int id)
|
|
||||||
{
|
|
||||||
BindingTree n;
|
|
||||||
|
|
||||||
if (!translate(button, n.binding, false))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BindingTree *p = _mousetree, **newp = &_mousetree;
|
|
||||||
while (p) {
|
|
||||||
if (p->binding == n.binding)
|
|
||||||
return false; // conflict
|
|
||||||
p = p->next_sibling;
|
|
||||||
newp = &p->next_sibling;
|
|
||||||
}
|
|
||||||
|
|
||||||
grabMouseOnAll(false); // ungrab everything
|
|
||||||
|
|
||||||
*newp = new BindingTree(id);
|
|
||||||
(*newp)->chain = false;
|
|
||||||
(*newp)->binding.key = n.binding.key;
|
|
||||||
(*newp)->binding.modifiers = n.binding.modifiers;
|
|
||||||
|
|
||||||
grabMouseOnAll(true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int OBBindings::remove_mouse(const std::string &button)
|
|
||||||
{
|
|
||||||
(void)button;
|
|
||||||
assert(false); // XXX: function not implemented yet
|
|
||||||
|
|
||||||
grabMouseOnAll(false); // ungrab everything
|
|
||||||
|
|
||||||
// do shit...
|
|
||||||
|
|
||||||
grabMouseOnAll(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void OBBindings::assimilate(BindingTree *node)
|
void OBBindings::assimilate(BindingTree *node)
|
||||||
{
|
{
|
||||||
BindingTree *a, *b, *tmp, *last;
|
BindingTree *a, *b, *tmp, *last;
|
||||||
|
@ -340,43 +289,6 @@ void OBBindings::remove_all()
|
||||||
remove_branch(_keytree.first_child);
|
remove_branch(_keytree.first_child);
|
||||||
_keytree.first_child = 0;
|
_keytree.first_child = 0;
|
||||||
}
|
}
|
||||||
BindingTree *p = _mousetree;
|
|
||||||
while (p) {
|
|
||||||
BindingTree *n = p->next_sibling;
|
|
||||||
delete p;
|
|
||||||
p = n;
|
|
||||||
}
|
|
||||||
_mousetree = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void OBBindings::grabMouse(bool grab, const OBClient *client)
|
|
||||||
{
|
|
||||||
BindingTree *p = _mousetree;
|
|
||||||
while (p) {
|
|
||||||
if (grab)
|
|
||||||
otk::OBDisplay::grabButton(p->binding.key, p->binding.modifiers,
|
|
||||||
client->frame->window(), false,
|
|
||||||
ButtonMotionMask | ButtonPressMask |
|
|
||||||
ButtonReleaseMask, GrabModeAsync,
|
|
||||||
GrabModeAsync, None, None, false);
|
|
||||||
else
|
|
||||||
otk::OBDisplay::ungrabButton(p->binding.key, p->binding.modifiers,
|
|
||||||
client->frame->window());
|
|
||||||
p = p->next_sibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void OBBindings::grabMouseOnAll(bool grab)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < Openbox::instance->screenCount(); ++i) {
|
|
||||||
OBScreen *s = Openbox::instance->screen(i);
|
|
||||||
assert(s);
|
|
||||||
OBScreen::ClientList::iterator it, end = s->clients.end();
|
|
||||||
for (it = s->clients.begin(); it != end; ++it)
|
|
||||||
grabMouse(grab, *it);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -408,38 +320,27 @@ void OBBindings::grabKeys(bool grab)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OBBindings::fire(OBActions::ActionType type, Window window,
|
void OBBindings::fire(Window window, unsigned int modifiers, unsigned int key,
|
||||||
unsigned int modifiers, unsigned int key, Time time)
|
Time time)
|
||||||
{
|
{
|
||||||
if (type == OBActions::Action_KeyPress) {
|
if (key == _resetkey.key && modifiers == _resetkey.modifiers) {
|
||||||
if (key == _resetkey.key && modifiers == _resetkey.modifiers) {
|
grabKeys(false);
|
||||||
grabKeys(false);
|
_curpos = &_keytree;
|
||||||
_curpos = &_keytree;
|
grabKeys(true);
|
||||||
grabKeys(true);
|
|
||||||
} else {
|
|
||||||
BindingTree *p = _curpos->first_child;
|
|
||||||
while (p) {
|
|
||||||
if (p->binding.key == key && p->binding.modifiers == modifiers) {
|
|
||||||
if (p->chain) {
|
|
||||||
grabKeys(false);
|
|
||||||
_curpos = p;
|
|
||||||
grabKeys(true);
|
|
||||||
} else {
|
|
||||||
python_callback_binding(p->id, type, window, modifiers, key, time);
|
|
||||||
grabKeys(false);
|
|
||||||
_curpos = &_keytree;
|
|
||||||
grabKeys(true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
p = p->next_sibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
BindingTree *p = _mousetree;
|
BindingTree *p = _curpos->first_child;
|
||||||
while (p) {
|
while (p) {
|
||||||
if (p->binding.key == key && p->binding.modifiers == modifiers) {
|
if (p->binding.key == key && p->binding.modifiers == modifiers) {
|
||||||
python_callback_binding(p->id, type, window, modifiers, key, time);
|
if (p->chain) {
|
||||||
|
grabKeys(false);
|
||||||
|
_curpos = p;
|
||||||
|
grabKeys(true);
|
||||||
|
} else {
|
||||||
|
python_callback_binding(p->id, type, window, modifiers, key, time);
|
||||||
|
grabKeys(false);
|
||||||
|
_curpos = &_keytree;
|
||||||
|
grabKeys(true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p = p->next_sibling;
|
p = p->next_sibling;
|
||||||
|
@ -447,5 +348,4 @@ void OBBindings::fire(OBActions::ActionType type, Window window,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,55 +49,36 @@ public:
|
||||||
typedef std::vector<std::string> StringVect;
|
typedef std::vector<std::string> StringVect;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BindingTree _keytree; // root node of the tree (this doesn't have siblings!)
|
BindingTree _tree; // root node of the tree (this doesn't have siblings!)
|
||||||
BindingTree *_curpos; // position in the keytree
|
BindingTree *_curpos; // position in the keytree
|
||||||
|
|
||||||
BindingTree *_mousetree; // this tree is a list. it has only siblings
|
|
||||||
|
|
||||||
Binding _resetkey; // the key which resets the key chain status
|
Binding _resetkey; // the key which resets the key chain status
|
||||||
|
|
||||||
int find_key(BindingTree *search) const;
|
int find(BindingTree *search) const;
|
||||||
bool translate(const std::string &str, Binding &b, bool askey) const;
|
bool translate(const std::string &str, Binding &b) const;
|
||||||
BindingTree *buildtree(const StringVect &keylist, int id) const;
|
BindingTree *buildtree(const StringVect &keylist, int id) const;
|
||||||
void assimilate(BindingTree *node);
|
void assimilate(BindingTree *node);
|
||||||
|
|
||||||
void grabMouseOnAll(bool grab);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Initializes an OBBinding object
|
//! Initializes an OBBinding object
|
||||||
OBBindings();
|
OBBindings();
|
||||||
//! Destroys the OBBinding object
|
//! Destroys the OBBinding object
|
||||||
virtual ~OBBindings();
|
virtual ~OBBindings();
|
||||||
|
|
||||||
//! Adds a new mouse binding
|
|
||||||
/*!
|
|
||||||
A binding will fail to be added if the binding already exists, or if the
|
|
||||||
string is invalid.
|
|
||||||
@return true if the binding could be added; false if it could not.
|
|
||||||
*/
|
|
||||||
bool add_mouse(const std::string &button, int id);
|
|
||||||
|
|
||||||
//! Removes a mouse binding
|
|
||||||
/*!
|
|
||||||
@return The id of the binding that was removed, or '< 0' if none were
|
|
||||||
removed.
|
|
||||||
*/
|
|
||||||
int remove_mouse(const std::string &button);
|
|
||||||
|
|
||||||
//! Adds a new key binding
|
//! Adds a new key binding
|
||||||
/*!
|
/*!
|
||||||
A binding will fail to be added if the binding already exists (as part of
|
A binding will fail to be added if the binding already exists (as part of
|
||||||
a chain or not), or if any of the strings in the keylist are invalid.
|
a chain or not), or if any of the strings in the keylist are invalid.
|
||||||
@return true if the binding could be added; false if it could not.
|
@return true if the binding could be added; false if it could not.
|
||||||
*/
|
*/
|
||||||
bool add_key(const StringVect &keylist, int id);
|
bool add(const StringVect &keylist, int id);
|
||||||
|
|
||||||
//! Removes a key binding
|
//! Removes a key binding
|
||||||
/*!
|
/*!
|
||||||
@return The id of the binding that was removed, or '< 0' if none were
|
@return The id of the binding that was removed, or '< 0' if none were
|
||||||
removed.
|
removed.
|
||||||
*/
|
*/
|
||||||
int remove_key(const StringVect &keylist);
|
int remove(const StringVect &keylist);
|
||||||
|
|
||||||
//! Removes all key bindings
|
//! Removes all key bindings
|
||||||
void remove_all();
|
void remove_all();
|
||||||
|
@ -107,14 +88,12 @@ public:
|
||||||
@return -1 if the keybinding was not found but does not conflict with
|
@return -1 if the keybinding was not found but does not conflict with
|
||||||
any others; -2 if the keybinding conflicts with another.
|
any others; -2 if the keybinding conflicts with another.
|
||||||
*/
|
*/
|
||||||
int find_key(const StringVect &keylist);
|
int find(const StringVect &keylist);
|
||||||
|
|
||||||
void fire(OBActions::ActionType type, Window window, unsigned int modifiers,
|
void fire(Window window, unsigned int modifiers,unsigned int key, Time time);
|
||||||
unsigned int key, Time time);
|
|
||||||
|
|
||||||
void setResetKey(const std::string &key);
|
void setResetKey(const std::string &key);
|
||||||
|
|
||||||
void grabMouse(bool grab, const OBClient *client);
|
|
||||||
void grabKeys(bool grab);
|
void grabKeys(bool grab);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -402,7 +402,7 @@ void OBScreen::manageWindow(Window window)
|
||||||
// update the root properties
|
// update the root properties
|
||||||
setClientList();
|
setClientList();
|
||||||
|
|
||||||
// grab buttons/keys on the window
|
// grab buttons on the window
|
||||||
Openbox::instance->bindings()->grabMouse(true, client);
|
Openbox::instance->bindings()->grabMouse(true, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ void OBScreen::unmanageWindow(OBClient *client)
|
||||||
{
|
{
|
||||||
OBFrame *frame = client->frame;
|
OBFrame *frame = client->frame;
|
||||||
|
|
||||||
// ungrab buttons/keys on the window
|
// ungrab buttons on the window
|
||||||
Openbox::instance->bindings()->grabMouse(false, client);
|
Openbox::instance->bindings()->grabMouse(false, client);
|
||||||
|
|
||||||
// XXX: pass around focus if this window was focused
|
// XXX: pass around focus if this window was focused
|
||||||
|
|
Loading…
Reference in a new issue