fixed focus key handler

This commit is contained in:
taiyu 2015-08-19 00:28:53 -07:00
parent 1bf02144e5
commit e16a4015ff
4 changed files with 103 additions and 112 deletions

View file

@ -10,6 +10,7 @@ extern swayc_t root_container;
void init_layout(void);
void add_child(swayc_t *parent, swayc_t *child);
void add_floating(swayc_t *ws, swayc_t *child);
// Returns parent container which needs to be rearranged.
swayc_t *add_sibling(swayc_t *sibling, swayc_t *child);
swayc_t *replace_child(swayc_t *child, swayc_t *new_child);

View file

@ -185,40 +185,23 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
int i;
// Change from nonfloating to floating
if (!view->is_floating) {
view->is_floating = true;
for (i = 0; i < view->parent->children->length; i++) {
if (view->parent->children->items[i] == view) {
// Try to use desired geometry to set w/h
remove_child(view);
add_floating(active_workspace,view);
view->x = (active_workspace->width - view->width)/2;
view->y = (active_workspace->height - view->height)/2;
arrange_windows(active_workspace, -1, -1);
if (view->desired_width != -1) {
view->width = view->desired_width;
}
if (view->desired_height != -1) {
view->height = view->desired_height;
}
// Swap from the list of whatever container the view was in
// to the workspace->floating list
list_del(view->parent->children, i);
list_add(active_workspace->floating, view);
destroy_container(view->parent);
// Set the new position of the container and arrange windows
view->x = (active_workspace->width - view->width)/2;
view->y = (active_workspace->height - view->height)/2;
sway_log(L_INFO, "Setting container %p to floating at coordinates X:%d Y:%d, W:%d, H:%d", view, view->x, view->y, view->width, view->height);
// Change parent to active_workspace
view->parent = active_workspace;
arrange_windows(active_workspace, -1, -1);
return true;
}
}
} else {
// Delete the view from the floating list and unset its is_floating flag
// Using length-1 as the index is safe because the view must be the currently
// focused floating output
list_del(active_workspace->floating, active_workspace->floating->length - 1);
remove_child(view);
view->is_floating = false;
active_workspace->focused = NULL;
// Get the properly focused container, and add in the view there
swayc_t *focused = container_under_pointer();
// If focused is null, it's because the currently focused container is a workspace

View file

@ -15,6 +15,7 @@
#include "focus.h"
uint32_t keys_pressed[32];
int keys_pressed_length = 0;
static struct wlc_origin mouse_origin;
@ -23,6 +24,15 @@ static bool dragging = false;
static bool m2_held = false;
static bool resizing = false;
static bool floating_mod_pressed(void) {
int i = 0;
while (i < keys_pressed_length) {
if (keys_pressed[i++] == config->floating_mod)
return true;
}
return false;
}
static bool pointer_test(swayc_t *view, void *_origin) {
const struct wlc_origin *origin = _origin;
// Determine the output that the view is under
@ -286,7 +296,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
return false;
}
static uint8_t head = 0;
bool cmd_success = false;
struct sway_mode *mode = config->current_mode;
@ -295,15 +304,15 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
// Find key, if it has been pressed
int mid = 0;
while (mid < head && keys_pressed[mid] != sym) {
while (mid < keys_pressed_length && keys_pressed[mid] != sym) {
++mid;
}
//Add or remove key depending on state
if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) {
keys_pressed[head++] = sym;
} else if (state == WLC_KEY_STATE_RELEASED && mid < head) {
memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid));
keys_pressed[head] = 0;
if (state == WLC_KEY_STATE_PRESSED && mid == keys_pressed_length && keys_pressed_length + 1 < QSIZE) {
keys_pressed[keys_pressed_length++] = sym;
} else if (state == WLC_KEY_STATE_RELEASED && mid < keys_pressed_length) {
memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--keys_pressed_length - mid));
keys_pressed[keys_pressed_length] = 0;
}
// TODO: reminder to check conflicts with mod+q+a versus mod+q
int i;
@ -317,7 +326,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
match = false;
xkb_keysym_t *key = binding->keys->items[j];
uint8_t k;
for (k = 0; k < head; ++k) {
for (k = 0; k < keys_pressed_length; ++k) {
if (keys_pressed[k] == *key) {
match = true;
break;
@ -333,9 +342,9 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
int j;
for (j = 0; j < binding->keys->length; ++j) {
uint8_t k;
for (k = 0; k < head; ++k) {
memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k));
keys_pressed[head] = 0;
for (k = 0; k < keys_pressed_length; ++k) {
memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--keys_pressed_length - k));
keys_pressed[keys_pressed_length] = 0;
break;
}
}
@ -355,38 +364,25 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
static wlc_handle prev_handle = 0;
mouse_origin = *origin;
bool changed_floating = false;
int i = 0;
if (!active_workspace) {
return false;
}
// Do checks to determine if proper keys are being held
swayc_t *view = active_workspace->focused;
swayc_t *view = get_focused_view(active_workspace);
uint32_t edge = 0;
if (dragging && view) {
if (view->is_floating) {
while (keys_pressed[i++]) {
if (keys_pressed[i] == config->floating_mod) {
if (dragging && view && view->is_floating) {
int dx = mouse_origin.x - prev_pos.x;
int dy = mouse_origin.y - prev_pos.y;
view->x += dx;
view->y += dy;
changed_floating = true;
break;
}
}
}
} else if (resizing && view) {
if (view->is_floating) {
while (keys_pressed[i++]) {
if (keys_pressed[i] == config->floating_mod) {
} else if (resizing && view && view->is_floating) {
int dx = mouse_origin.x - prev_pos.x;
int dy = mouse_origin.y - prev_pos.y;
// Move and resize the view based on the dx/dy and mouse position
int midway_x = view->x + view->width/2;
int midway_y = view->y + view->height/2;
if (dx < 0) {
changed_floating = true;
if (mouse_origin.x > midway_x) {
@ -431,10 +427,6 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
edge += WLC_RESIZE_EDGE_TOP;
}
}
break;
}
}
}
}
if (config->focus_follows_mouse && prev_handle != handle) {
//Dont change focus if fullscreen
@ -489,9 +481,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
}
}
arrange_windows(pointer->parent, -1, -1);
if (floating_mod_pressed()) {
dragging = m1_held;
resizing = m2_held;
return true;
}
//Dont want pointer sent to window while dragging or resizing
return (dragging || resizing);
}
return (pointer && pointer != focused);
} else {

View file

@ -38,6 +38,17 @@ void add_child(swayc_t *parent, swayc_t *child) {
}
}
void add_floating(swayc_t *ws, swayc_t *child) {
sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type,
child->width, child->height, ws, ws->type, ws->width, ws->height);
list_add(ws->floating, child);
child->parent = ws;
child->is_floating = true;
if (!ws->focused) {
ws->focused = child;
}
}
swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) {
swayc_t *parent = sibling->parent;
int i = index_child(parent, sibling);
@ -76,6 +87,7 @@ swayc_t *remove_child(swayc_t *child) {
break;
}
}
i = 0;
} else {
for (i = 0; i < parent->children->length; ++i) {
if (parent->children->items[i] == child) {