Example #1
0
func (slct *Select) keyResponse() xevent.KeyPressFun {
	f := func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
		if !slct.showing {
			return
		}

		beforeLen := len(slct.input.Text)
		mods, kc := keybind.DeduceKeyInfo(ev.State, ev.Detail)

		slct.input.Add(mods, kc)

		switch {
		case keybind.KeyMatch(X, slct.config.BackspaceKey, mods, kc):
			slct.input.Remove()
		case keybind.KeyMatch(X, slct.config.CancelKey, mods, kc):
			slct.Hide()
			return
		case keybind.KeyMatch(X, slct.config.ConfirmKey, mods, kc):
			if slct.selected >= 0 && slct.selected < len(slct.items) {
				slct.items[slct.selected].choose()
				slct.Hide()
			} else if len(slct.items) == 1 {
				slct.items[0].choose()
				slct.Hide()
			}
			return
		case keybind.KeyMatch(X, "Tab", mods, kc) ||
			keybind.KeyMatch(X, "ISO_Left_Tab", mods, kc):

			if len(slct.items) == 0 {
				break
			}
			if mods&xproto.ModMaskShift > 0 {
				if slct.selected == -1 {
					slct.selected++
				}
				slct.selected = misc.Mod(slct.selected-1, len(slct.items))
			} else {
				slct.selected = misc.Mod(slct.selected+1, len(slct.items))
			}
			slct.highlight()
		}

		// If the length of the input changed, then re-evaluate completion
		if beforeLen != len(slct.input.Text) {
			slct.FilterItems(string(slct.input.Text))
			slct.selected = -1
			slct.highlight()
		}
	}
	return xevent.KeyPressFun(f)
}
Example #2
0
func (hds *Heads) PrevWorkspace() *workspace.Workspace {
	if cur := hds.GlobalIndex(hds.ActiveWorkspace()); cur > -1 {
		// I f*****g hate Go's modulo operator. WTF.
		prev := misc.Mod(cur-1, len(hds.Workspaces.Wrks))
		return hds.Workspaces.Get(prev)
	}
	panic("bug")
}
Example #3
0
func (cmd HeadCycle) Run() gribble.Value {
	return syncRun(func() gribble.Value {
		cur := wm.Heads.VisibleIndex(wm.Workspace())
		next := misc.Mod(cur+1, wm.Heads.NumHeads())
		wm.Heads.WithVisibleWorkspace(next,
			func(wrk *workspace.Workspace) {
				wm.SetWorkspace(wrk, false)
			})
		wm.FocusFallback()
		return nil
	})
}
Example #4
0
// Prev will highlight the previous choice in the dialog.
func (cycle *Cycle) Prev() {
	if !cycle.showing {
		return
	}

	if cycle.selected == -1 {
		cycle.selected = len(cycle.items) - 1
	} else {
		cycle.selected--
	}

	cycle.selected = misc.Mod(cycle.selected, len(cycle.items))
	cycle.highlight()
}
Example #5
0
// Next will highlight the next choice in the dialog.
func (cycle *Cycle) Next() {
	if !cycle.showing {
		return
	}

	if cycle.selected == -1 {
		if len(cycle.items) > 1 {
			cycle.selected = 1
		} else {
			cycle.selected = 0
		}
	} else {
		cycle.selected++
	}

	cycle.selected = misc.Mod(cycle.selected, len(cycle.items))
	cycle.highlight()
}