2 #define I3__FILE__ "click.c"
17 #include <xcb/xcb_icccm.h>
19 #include <X11/XKBlib.h>
32 DLOG(
"border = %d, con = %p\n", border, con);
44 search_direction =
D_UP;
56 LOG(
"No second container in this direction found.\n");
60 assert(first != second);
64 if (search_direction ==
D_UP || search_direction ==
D_LEFT) {
74 DLOG(
"After resize handler, rendering\n");
91 int to_right = con->
rect.
width -
event->event_x,
92 to_left =
event->event_x,
93 to_top =
event->event_y,
96 DLOG(
"click was %d px to the right, %d px to the left, %d px to top, %d px to bottom\n",
97 to_right, to_left, to_top, to_bottom);
99 if (to_right < to_left &&
101 to_right < to_bottom)
104 if (to_left < to_right &&
109 if (to_top < to_right &&
114 if (to_bottom < to_right &&
115 to_bottom < to_left &&
129 DLOG(
"BORDER x = %d, y = %d for con %p, window 0x%08x\n",
130 event->event_x, event->event_y, con, event->event);
141 Con *check_con = con;
143 check_con = check_con->
parent;
149 DLOG(
"Not handling this resize, this container has > 1 child.\n");
155 if (event->event_x >= 0 && event->event_x <= (int32_t)bsr.
x &&
156 event->event_y >= (int32_t)bsr.
y && event->event_y <= (int32_t)(con->
rect.
height + bsr.
height))
160 event->event_y >= (int32_t)bsr.
y && event->event_y <= (int32_t)(con->
rect.
height + bsr.
height))
175 DLOG(
"--> click properties: mod = %d, destination = %d\n", mod_pressed, dest);
176 DLOG(
"--> OUTCOME = %p\n", con);
194 xcb_allow_events(
conn, XCB_ALLOW_ASYNC_POINTER, event->time);
207 if (event->response_type == XCB_BUTTON_RELEASE) {
223 if (ws != focused_workspace)
228 const bool proportional = (
event->state &
BIND_SHIFT);
234 (event->detail == XCB_BUTTON_INDEX_4 ||
235 event->detail == XCB_BUTTON_INDEX_5)) {
236 DLOG(
"Scrolling on a window decoration\n");
248 bool scroll_prev_possible = (
TAILQ_PREV(focused, nodes_head, nodes) != NULL);
249 bool scroll_next_possible = (
TAILQ_NEXT(focused, nodes) != NULL);
250 if (event->detail == XCB_BUTTON_INDEX_4 && scroll_prev_possible)
252 else if (event->detail == XCB_BUTTON_INDEX_5 && scroll_next_possible)
263 if (floatingcon != NULL && fs != con) {
267 if (mod_pressed && event->detail == XCB_BUTTON_INDEX_1) {
275 if (mod_pressed && event->detail == XCB_BUTTON_INDEX_3) {
276 DLOG(
"floating resize due to floatingmodifier\n");
283 DLOG(
"tiling resize with fallback\n");
289 DLOG(
"floating resize due to decoration right click\n");
295 DLOG(
"floating resize due to border click\n");
317 if (dest ==
CLICK_INSIDE && mod_pressed && event->detail == XCB_BUTTON_INDEX_3) {
323 (event->detail == XCB_BUTTON_INDEX_1 ||
324 event->detail == XCB_BUTTON_INDEX_3)) {
325 DLOG(
"Trying to resize (tiling)\n");
330 xcb_allow_events(
conn, XCB_ALLOW_REPLAY_POINTER, event->time);
347 DLOG(
"Button %d %s on window 0x%08x (child 0x%08x) at (%d, %d) (root %d, %d)\n",
348 event->state, (event->response_type == XCB_BUTTON_PRESS ?
"press" :
"release"),
349 event->event, event->child, event->event_x, event->event_y, event->root_x,
355 const bool mod_pressed = (mod != 0 && (
event->state & mod) == mod);
356 DLOG(
"floating_mod = %d, detail = %d\n", mod_pressed, event->detail);
363 if (event->event ==
root && event->response_type == XCB_BUTTON_PRESS) {
380 ELOG(
"Clicked into unknown window?!\n");
381 xcb_allow_events(
conn, XCB_ALLOW_REPLAY_POINTER, event->time);
395 if (event->child != XCB_NONE) {
396 DLOG(
"event->child not XCB_NONE, so this is an event which originated from a click into the application, but the application did not handle it.\n");
void tree_next(char way, orientation_t orientation)
Changes focus in the given way (next/previous) and given orientation (horizontal/vertical).
static bool tiling_resize(Con *con, xcb_button_press_event_t *event, const click_destination_t dest)
void floating_resize_window(Con *con, const bool proportional, const xcb_button_press_event_t *event)
Called when the user clicked on a floating window while holding the floating_modifier and the right m...
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, const xcb_button_press_event_t *event)
Stores a rectangle, for example the size of a window, the child window etc.
int handle_button_press(xcb_button_press_event_t *event)
The button press X callback.
void floating_drag_window(Con *con, const xcb_button_press_event_t *event)
Called when the user clicked on the titlebar of a floating window.
void workspace_show(Con *workspace)
Switches to the given workspace.
#define TAILQ_FIRST(head)
xcb_timestamp_t last_timestamp
The last timestamp we got from X11 (timestamps are included in some events and are used for some thin...
#define TAILQ_NEXT(elm, field)
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
void command_result_free(CommandResult *result)
Frees a CommandResult.
bool rect_contains(Rect rect, uint32_t x, uint32_t y)
Holds a keybinding, consisting of a keycode combined with modifiers and the command which is executed...
CommandResult * run_binding(Binding *bind, Con *con)
Runs the given binding and handles parse errors.
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists...
A struct that contains useful information about the result of a command as a whole (e...
border_t
On which border was the dragging initiated?
void floating_raise_con(Con *con)
Raises the given container in the list of floating containers.
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
Rect con_border_style_rect(Con *con)
Returns a "relative" Rect which contains the amount of pixels that need to be added to the original R...
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
static int route_click(Con *con, xcb_button_press_event_t *event, const bool mod_pressed, const click_destination_t dest)
void con_focus(Con *con)
Sets input focus to the given container.
Con * con_by_frame_id(xcb_window_t frame)
Returns the container with the given frame ID or NULL if no such container exists.
int con_num_children(Con *con)
Returns the number of children of this container.
bool whole_window
If this is true for a mouse binding, the binding should be executed when the button is pressed over a...
#define TAILQ_PREV(elm, headname, field)
orientation_t con_orientation(Con *con)
Returns the orientation of the given container (for stacked containers, vertical orientation is used ...
A 'Con' represents everything from the X11 root window down to a single X11 window.
Binding * get_binding_from_xcb_event(xcb_generic_event_t *event)
Returns a pointer to the Binding that matches the given xcb event or NULL if no such binding exists...
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction)
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
uint32_t floating_modifier
The modifier which needs to be pressed in combination with your mouse buttons to do things with float...
#define TAILQ_FOREACH(var, head, field)
static bool tiling_resize_for_border(Con *con, border_t border, xcb_button_press_event_t *event)
static bool floating_mod_on_tiled_client(Con *con, xcb_button_press_event_t *event)