當前位置: 首頁>>代碼示例>>Golang>>正文


Golang XUtil.Keybinds方法代碼示例

本文整理匯總了Golang中github.com/BurntSushi/xgbutil.XUtil.Keybinds方法的典型用法代碼示例。如果您正苦於以下問題:Golang XUtil.Keybinds方法的具體用法?Golang XUtil.Keybinds怎麽用?Golang XUtil.Keybinds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/BurntSushi/xgbutil.XUtil的用法示例。


在下文中一共展示了XUtil.Keybinds方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: updateMaps

// updateMaps runs in response to MappingNotify events.
// It is responsible for making sure our view of the world's keyboard
// and modifier maps is correct. (Pointer mappings should be handled in
// a similar callback in the mousebind package.)
func updateMaps(xu *xgbutil.XUtil, e xevent.MappingNotifyEvent) {
	keyMap, modMap := MapsGet(xu)

	// So we used to go through the old mapping and the new mapping and pick
	// out precisely where there are changes. But after allowing for a
	// one-to-many mapping from keysym to keycodes, this process became too
	// complex. So we're going to bust out our hammer and rebind everything
	// based on the initial key strings.
	if e.Request == xproto.MappingKeyboard {
		// We must ungrab everything first, in case two keys are being swapped.
		keys := keyKeys(xu)
		for _, key := range keys {
			Ungrab(xu, key.Win, key.Mod, key.Code)
			detach(xu, key.Evtype, key.Win)
		}

		// Wipe the slate clean.
		xu.KeybindsLck.Lock()
		xu.Keybinds = make(map[xgbutil.KeyKey][]xgbutil.CallbackKey, len(keys))
		xu.Keygrabs = make(map[xgbutil.KeyKey]int, len(keys))
		keyStrs := xu.Keystrings
		xu.KeybindsLck.Unlock()

		// Update our mappings before rebinding.
		KeyMapSet(xu, keyMap)
		ModMapSet(xu, modMap)

		// Now rebind everything in Keystrings
		for _, ks := range keyStrs {
			err := connect(xu,
				ks.Callback, ks.Evtype, ks.Win, ks.Str, ks.Grab, true)
			if err != nil {
				xgbutil.Logger.Println(err)
			}
		}
	} else {
		// We don't have to do something with MappingModifier like we do with
		// MappingKeyboard. This is due to us requiring that key strings use
		// modifier names built into X. (i.e., the names seen in the output of
		// `xmodmap`.) This means that the modifier mappings happen on the X
		// server side, so we don't *typically* have to care what key is
		// actually being pressed to trigger a modifier. (There are some
		// exceptional cases, and when that happens, we simply query on-demand
		// which keys are modifiers. See the RunKey{Press,Release}Callbacks
		// functions in keybind/callback.go for the deets.)
		KeyMapSet(xu, keyMap)
		ModMapSet(xu, modMap)
	}
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:53,代碼來源:keybind.go


注:本文中的github.com/BurntSushi/xgbutil.XUtil.Keybinds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。