about summary refs log tree commit diff stats
path: root/config.def.h
Commit message (Expand)AuthorAgeFilesLines
* we need a tagset per monitor, removed tagset declaration from config.hAnselm R Garbe2009-06-201-1/+0
* experimental xinerama support, two new actions, Mod1-w/e and Mod1-Shift-w/eAnselm R Garbe2009-06-201-1/+9
* removed MAXTAGLENAnselm R Garbe2009-05-291-2/+2
* applied Gottox' patches, and also removed usegrabAnselm R Garbe2009-03-171-2/+0
* applied Neale Pickett's xprop status reading patch, updated README and dwm.1 ...a@null2008-12-121-1/+0
* several changes towards 5.3, XINERAMA is disabled by default, introduced useg...Anselm R Garbe2008-10-191-0/+2
* introduced NOBORDER macro to hide the nasty - 2 * c->bw in various calculatio...Anselm R Garbe2008-08-271-0/+1
* added a comment about FAQ regarding mfact meaningAnselm R Garbe2008-08-181-1/+1
* made readin a config.h variableAnselm R Garbe2008-08-021-0/+1
* make hg tip compilable with default configPremysl Hruby2008-07-181-2/+2
* got rid of compile time xidx configuration, querying mouse pointer insteadAnselm R Garbe2008-07-161-4/+0
* removed useless commentAnselm R Garbe2008-07-021-1/+1
* removed useless charactersAnselm R Garbe2008-06-241-3/+3
* applied Gottox' ClkTagBar patchAnselm R Garbe2008-06-201-15/+4
* untested monocleAnselm R Garbe2008-06-191-6/+9
* branch merge 5.0Anselm R Garbe2008-06-171-1/+1
|\
| * s/tags ref/tags mask/arg@suckless.org2008-06-151-1/+1
* | tiled layout resizehints should be respected by defaultAnselm R Garbe2008-06-171-2/+2
|/
* removed scroll-wheel based focussing on window title clicksAnselm R Garbe2008-06-141-2/+0
* fix of swapped focusstack mouse buttonsAnselm R Garbe2008-06-141-2/+2
* removed root window click handlingAnselm R Garbe2008-06-141-1/+0
* removed font and color definitionsAnselm R Garbe2008-06-141-18/+21
* updateAnselm R Garbe2008-06-121-1/+1
* integrated yiyus mouse.diff (though the bar click handling is slightly broken...Anselm R Garbe2008-06-111-25/+59
* made Xinerama screen index customizableAnselm R Garbe2008-06-111-4/+8
* added nsz' patchAnselm R Garbe2008-06-111-0/+3
* integrated Peter Hartlich's patch, removed const char *c from union, simplifi...Anselm R Garbe2008-06-111-4/+4
* applied anydot's patchset.diffAnselm R Garbe2008-06-111-35/+35
* Gottox' drawtext simplificationAnselm R Garbe2008-06-011-1/+1
* applied noviewprev.diff, fix.diff and unusedflags.diffAnselm R Garbe2008-06-011-1/+1
* removed Layout->updategeom, unnecessaryAnselm R Garbe2008-05-261-3/+3
* applied yiyus domax patch with slight modificationsAnselm R Garbe2008-05-261-36/+16
* s/int/uint/ in config.hAnselm R Garbe2008-05-221-38/+38
* setmfact argument was wrongAnselm R Garbe2008-05-221-2/+2
* applied Gottox bitmask + void *arg patchAnselm R Garbe2008-05-221-43/+44
* merged tile.c again into dwm.canselm@anselm12008-05-191-3/+1
* recent changes, introduced togglebar, changed some defines into variable decl...Anselm R Gar
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.

from __future__ import (absolute_import, division, print_function)

import curses


class MouseEvent(object):
    PRESSED = [
        0,
        curses.BUTTON1_PRESSED,
        curses.BUTTON2_PRESSED,
        curses.BUTTON3_PRESSED,
        curses.BUTTON4_PRESSED,
    ]
    CTRL_SCROLLWHEEL_MULTIPLIER = 5

    def __init__(self, getmouse):
        """Creates a MouseEvent object from the result of win.getmouse()"""
        _, self.x, self.y, _, self.bstate = getmouse

        # x-values above ~220 suddenly became negative, apparently
        # it's sufficient to add 0xFF to fix that error.
        if self.x < 0:
            self.x += 0xFF

        if self.y < 0:
            self.y += 0xFF

    def pressed(self, n):
        """Returns whether the mouse key n is pressed"""
        try:
            return (self.bstate & MouseEvent.PRESSED[n]) != 0
        except IndexError:
            return False

    def mouse_wheel_direction(self):
        """Returns the direction of the scroll action, 0 if there was none"""
        # If the bstate > ALL_MOUSE_EVENTS, it's an invalid mouse button.
        # I interpret invalid buttons as "scroll down" because all tested
        # systems have a broken curses implementation and this is a workaround.
        # Recently it seems to have been fixed, as 2**21 was introduced as
        # the code for the "scroll down" button.
        if self.bstate & curses.BUTTON4_PRESSED:
            return -self.CTRL_SCROLLWHEEL_MULTIPLIER if self.ctrl() else -1
        elif self.bstate & curses.BUTTON2_PRESSED \
                or self.bstate & 2**21 \
                or self.bstate > curses.ALL_MOUSE_EVENTS:
            return self.CTRL_SCROLLWHEEL_MULTIPLIER if self.ctrl() else 1
        return 0

    def ctrl(self):
        return self.bstate & curses.BUTTON_CTRL

    def alt(self):
        return self.bstate & curses.BUTTON_ALT

    def shift(self):
        return self.bstate & curses.BUTTON_SHIFT

    def key_invalid(self):
        return self.bstate > curses.ALL_MOUSE_EVENTS