Skip to content

Commit 48c0c4e

Browse files
committed
Dedupe handling of mouse buttons in macos backend.
AFAICT `mouseDown()` and friends already check `[event type]` and correctly handle right/middle button events, so the other event handlers can just defer to them. The point of the deduplication is so that future event rearchitecting doesn't have to repeat loads of keyboard-modifiers handling code in each of these handlers.
1 parent 471b914 commit 48c0c4e

File tree

1 file changed

+6
-121
lines changed

1 file changed

+6
-121
lines changed

src/_macosx.m

Lines changed: 6 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,127 +1885,12 @@ - (void)mouseDragged:(NSEvent *)event
18851885
PyGILState_Release(gstate);
18861886
}
18871887

1888-
- (void)rightMouseDown:(NSEvent *)event
1889-
{
1890-
int x, y;
1891-
int num = 3;
1892-
int dblclick = 0;
1893-
PyObject* result;
1894-
PyGILState_STATE gstate;
1895-
NSPoint location = [event locationInWindow];
1896-
location = [self convertPoint: location fromView: nil];
1897-
x = location.x * device_scale;
1898-
y = location.y * device_scale;
1899-
gstate = PyGILState_Ensure();
1900-
if ([event clickCount] == 2) {
1901-
dblclick = 1;
1902-
}
1903-
result = PyObject_CallMethod(canvas, "button_press_event", "iiii", x, y, num, dblclick);
1904-
if(result)
1905-
Py_DECREF(result);
1906-
else
1907-
PyErr_Print();
1908-
1909-
PyGILState_Release(gstate);
1910-
}
1911-
1912-
- (void)rightMouseUp:(NSEvent *)event
1913-
{
1914-
int x, y;
1915-
int num = 3;
1916-
PyObject* result;
1917-
PyGILState_STATE gstate;
1918-
NSPoint location = [event locationInWindow];
1919-
location = [self convertPoint: location fromView: nil];
1920-
x = location.x * device_scale;
1921-
y = location.y * device_scale;
1922-
gstate = PyGILState_Ensure();
1923-
result = PyObject_CallMethod(canvas, "button_release_event", "iii", x, y, num);
1924-
if(result)
1925-
Py_DECREF(result);
1926-
else
1927-
PyErr_Print();
1928-
1929-
PyGILState_Release(gstate);
1930-
}
1931-
1932-
- (void)rightMouseDragged:(NSEvent *)event
1933-
{
1934-
int x, y;
1935-
NSPoint location = [event locationInWindow];
1936-
location = [self convertPoint: location fromView: nil];
1937-
x = location.x * device_scale;
1938-
y = location.y * device_scale;
1939-
PyGILState_STATE gstate = PyGILState_Ensure();
1940-
PyObject* result = PyObject_CallMethod(canvas, "motion_notify_event", "ii", x, y);
1941-
if(result)
1942-
Py_DECREF(result);
1943-
else
1944-
PyErr_Print();
1945-
1946-
PyGILState_Release(gstate);
1947-
}
1948-
1949-
- (void)otherMouseDown:(NSEvent *)event
1950-
{
1951-
int x, y;
1952-
int num = 2;
1953-
int dblclick = 0;
1954-
PyObject* result;
1955-
PyGILState_STATE gstate;
1956-
NSPoint location = [event locationInWindow];
1957-
location = [self convertPoint: location fromView: nil];
1958-
x = location.x * device_scale;
1959-
y = location.y * device_scale;
1960-
gstate = PyGILState_Ensure();
1961-
if ([event clickCount] == 2) {
1962-
dblclick = 1;
1963-
}
1964-
result = PyObject_CallMethod(canvas, "button_press_event", "iiii", x, y, num, dblclick);
1965-
if(result)
1966-
Py_DECREF(result);
1967-
else
1968-
PyErr_Print();
1969-
1970-
PyGILState_Release(gstate);
1971-
}
1972-
1973-
- (void)otherMouseUp:(NSEvent *)event
1974-
{
1975-
int x, y;
1976-
int num = 2;
1977-
PyObject* result;
1978-
PyGILState_STATE gstate;
1979-
NSPoint location = [event locationInWindow];
1980-
location = [self convertPoint: location fromView: nil];
1981-
x = location.x * device_scale;
1982-
y = location.y * device_scale;
1983-
gstate = PyGILState_Ensure();
1984-
result = PyObject_CallMethod(canvas, "button_release_event", "iii", x, y, num);
1985-
if(result)
1986-
Py_DECREF(result);
1987-
else
1988-
PyErr_Print();
1989-
1990-
PyGILState_Release(gstate);
1991-
}
1992-
1993-
- (void)otherMouseDragged:(NSEvent *)event
1994-
{
1995-
int x, y;
1996-
NSPoint location = [event locationInWindow];
1997-
location = [self convertPoint: location fromView: nil];
1998-
x = location.x * device_scale;
1999-
y = location.y * device_scale;
2000-
PyGILState_STATE gstate = PyGILState_Ensure();
2001-
PyObject* result = PyObject_CallMethod(canvas, "motion_notify_event", "ii", x, y);
2002-
if(result)
2003-
Py_DECREF(result);
2004-
else
2005-
PyErr_Print();
2006-
2007-
PyGILState_Release(gstate);
2008-
}
1888+
- (void)rightMouseDown:(NSEvent *)event { [self mouseDown: event]; }
1889+
- (void)rightMouseUp:(NSEvent *)event { [self mouseUp: event]; }
1890+
- (void)rightMouseDragged:(NSEvent *)event { [self mouseDragged: event]; }
1891+
- (void)otherMouseDown:(NSEvent *)event { [self mouseDown: event]; }
1892+
- (void)otherMouseUp:(NSEvent *)event { [self mouseUp: event]; }
1893+
- (void)otherMouseDragged:(NSEvent *)event { [self mouseDragged: event]; }
20091894

20101895
- (void)setRubberband:(NSRect)rect
20111896
{

0 commit comments

Comments
 (0)