Ejemplo n.º 1
0
static void handle_output_focused(wlc_handle output, bool focus) {
    swayc_t *c = get_swayc_for_handle(output, &root_container);
    if (!c) return;
    if (focus) {
        unfocus_all(&root_container);
        focus_view(c);
    }
}
Ejemplo n.º 2
0
void Desktop::select_only(DesktopIcon *ic) { 
	E_ASSERT(ic != NULL);

	unfocus_all();
	selectionbuf.clear();
	selectionbuf.push_back(ic);

	ic->do_focus();
	ic->fast_redraw();
}
Ejemplo n.º 3
0
static bool handle_view_created(wlc_handle handle) {
    swayc_t *focused = get_focused_container(&root_container);
    uint32_t type = wlc_view_get_type(handle);
    // If override_redirect/unmanaged/popup/modal/splach
    if (type) {
        sway_log(L_DEBUG,"Unmanaged window of type %x left alone", type);
        wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
        if (type & WLC_BIT_UNMANAGED) {
            return true;
        }
        // For things like Dmenu
        if (type & WLC_BIT_OVERRIDE_REDIRECT) {
            override_redirect = true;
            wlc_view_focus(handle);
        }

        // Float popups
        if (type & WLC_BIT_POPUP) {
            swayc_t *view = new_floating_view(handle);
            wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, false);
            focus_view(view);
            arrange_windows(active_workspace, -1, -1);
        }
    } else {
        swayc_t *view = new_view(focused, handle);
        //Set maximize flag for windows.
        //TODO: floating windows have this unset
        wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true);
        unfocus_all(&root_container);
        focus_view(view);
        arrange_windows(view->parent, -1, -1);
    }
    if (wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) {
        unfocus_all(&root_container);
        focus_view(focused);
        arrange_windows(focused, -1, -1);
    }
    return true;
}
Ejemplo n.º 4
0
swayc_t *focus_pointer(void) {
    swayc_t *focused = get_focused_container(&root_container);
    if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) {
        swayc_t *pointer = find_container(&root_container, pointer_test, &mouse_origin);
        if (pointer && focused != pointer) {
            unfocus_all(&root_container);
            focus_view(pointer);
        } else if (!focused) {
            focus_view(active_workspace);
        }
        focused = pointer;
    }
    return focused;
}
Ejemplo n.º 5
0
int Desktop::handle(int event) {
	switch(event) {
		case FL_FOCUS:
		case FL_UNFOCUS:
		case FL_SHORTCUT:
			return 1;

		case FL_PUSH: {
			/*
			 * First check where we clicked. If we do it on desktop unfocus any possible focused childs, and handle
			 * specific clicks. Otherwise, do rest for childs.
			 */
			Fl_Widget* clicked = Fl::belowmouse();
			
			if(NOT_SELECTABLE(clicked)) {
				//E_DEBUG(E_STRLOC ": DESKTOP CLICK !!!\n");
				if(!selectionbuf.empty()) {
					/*
					 * Only focused are in selectionbuf, so this is fine to do; also will prevent 
					 * full redraw when is clicked on desktop
					 */
					unfocus_all();
					selectionbuf.clear();
				}

				/* track position so moving can be deduced */
				if(Fl::event_button() == 1) {
					selbox->x = Fl::event_x();
					selbox->y = Fl::event_y();
				} else if(Fl::event_button() == 3) {
					last_px = Fl::event_x();
					last_py = Fl::event_y();

					damage(EDE_DESKTOP_DAMAGE_OVERLAY);
					const edelib::MenuItem* item = dmenu->menu()->popup(Fl::event_x(), Fl::event_y());
					dmenu->picked(item);
				}

				return 1;
			}

			/* from here, all events are managed for icons */
			DesktopIcon* tmp_icon = (DesktopIcon*)clicked;

			/* do no use assertion on this, since fltk::belowmouse() can miss our icon */
			if(!tmp_icon) return 1;

			if(SELECTION_MULTI) {
				Fl::event_is_click(0);
				select(tmp_icon);
				return 1;
			} else if(SELECTION_SINGLE) {
				if(!in_selection(tmp_icon)) {
					select_only(tmp_icon);
				}
			} else if(Fl::event_button() == 3) {
				select_only(tmp_icon);
			}

			/* 
			 * Let child handle the rest.
			 * Also prevent click on other mouse buttons during move.
			 */
			if(!moving)
				tmp_icon->handle(FL_PUSH);

			//E_DEBUG(E_STRLOC ": FL_PUSH from desktop\n");
			selection_x = Fl::event_x_root();
			selection_y = Fl::event_y_root();
	
			return 1;
		 }

		case FL_DRAG:
			moving = true;
			if(!selectionbuf.empty()) {
				//E_DEBUG(E_STRLOC ": DRAG icon from desktop\n");
				move_selection(Fl::event_x_root(), Fl::event_y_root(), false);
			} else {
				//E_DEBUG(E_STRLOC ": DRAG from desktop\n");
				/*
				 * Moving is started with pushed button.
				 * From this point selection box is created and is rolled until release
				 */
				if(selbox->x != 0 || selbox->y != 0) {
					selbox->w = Fl::event_x() - selbox->x;
					selbox->h = Fl::event_y() - selbox->y;

					selbox->show = true;

					/* see if there some icons inside selection area */
					select_in_area();

					/* redraw selection box */
					damage(EDE_DESKTOP_DAMAGE_OVERLAY);
				}
			}

			return 1;

		case FL_RELEASE:
			//E_DEBUG(E_STRLOC ": RELEASE from desktop\n");
			//E_DEBUG(E_STRLOC ": clicks: %i\n", Fl::event_is_click());

			if(selbox->show) {
				selbox->x = selbox->y = selbox->w = selbox->h = 0;
				selbox->show = false;
				damage(EDE_DESKTOP_DAMAGE_OVERLAY);

				/*
				 * Now pickup those who are in is_focused() state.
				 *
				 * Possible flickers due overlay will be later removed when is called move_selection(), which 
				 * will in turn redraw icons again after position them.
				 */
				if(!selectionbuf.empty())
					selectionbuf.clear();

				DesktopIcon *o;
				for(int i = 0; i < children(); i++) {
					if(NOT_SELECTABLE(child(i))) continue;

					o = (DesktopIcon*)child(i);
					if(o->is_focused())
						select(o, false);
				}

				return 1;
			}

			if(!selectionbuf.empty() && moving)
				move_selection(Fl::event_x_root(), Fl::event_y_root(), true);

			/* 
			 * Do not send FL_RELEASE during move
			 * TODO: should be alowed FL_RELEASE to multiple icons? (aka. run command for all selected icons)?
			 */
			if(selectionbuf.size() == 1 && !moving)
				selectionbuf.front()->handle(FL_RELEASE);

			moving = false;
			return 1;

		case FL_DND_ENTER:
		case FL_DND_DRAG:
		case FL_DND_LEAVE:
			return 1;

		case FL_DND_RELEASE: {
			DesktopIcon* di = below_mouse(Fl::event_x(), Fl::event_y());
			if(di) return di->handle(event);
			return 1;
		}

		case FL_PASTE: {
			DesktopIcon* di = below_mouse(Fl::event_x(), Fl::event_y());
			if(di) return di->handle(event);
			return 1;
		}

		case FL_ENTER:
		case FL_LEAVE:
		case FL_MOVE:
			return EDE_DESKTOP_WINDOW::handle(event);

		default:
			break;
	}

	return 0;
}
Ejemplo n.º 6
0
int move_focus(enum movement_direction direction) {
	swayc_t *current = get_focused_container(&root_container);
	swayc_t *parent = current->parent;

	if (direction == MOVE_PARENT) {
		current = parent;
		parent  = parent->parent;
		if (parent->type == C_ROOT) {
			sway_log(L_DEBUG, "Focus cannot move to parent");
			return 1;
		} else {
			sway_log(L_DEBUG, "Moving focus away from %p", current);
			unfocus_all(parent);
			focus_view(parent);
			return 0;
		}
	}

	while (true) {
		sway_log(L_DEBUG, "Moving focus away from %p", current);

		// Test if we can even make a difference here
		bool can_move = false;
		int diff = 0;
		if (direction == MOVE_LEFT || direction == MOVE_RIGHT) {
			if (parent->layout == L_HORIZ) {
				can_move = true;
				diff = direction == MOVE_LEFT ? -1 : 1;
			}
		} else {
			if (parent->layout == L_VERT) {
				can_move = true;
				diff = direction == MOVE_UP ? -1 : 1;
			}
		}
		sway_log(L_DEBUG, "Can move? %s", can_move ? "yes" : "no");
		if (can_move) {
			int i;
			for (i = 0; i < parent->children->length; ++i) {
				swayc_t *child = parent->children->items[i];
				if (child == current) {
					break;
				}
			}
			int desired = i + diff;
			sway_log(L_DEBUG, "Moving from %d to %d", i, desired);
			if (desired < 0 || desired >= parent->children->length) {
				can_move = false;
			} else {
				unfocus_all(&root_container);
				focus_view(parent->children->items[desired]);
				return 0;
			}
		}
		if (!can_move) {
			sway_log(L_DEBUG, "Can't move at current level, moving up tree");
			current = parent;
			parent = parent->parent;
			if (parent->type == C_ROOT) {
				// Nothing we can do
				return 1;
			}
		}
	}
}