本文整理匯總了Golang中github.com/Nightgunner5/xgbutil.XUtil類的典型用法代碼示例。如果您正苦於以下問題:Golang XUtil類的具體用法?Golang XUtil怎麽用?Golang XUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了XUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MapsGet
// A convenience function to grab the KeyboardMapping and ModifierMapping
// from X. We need to do this on startup (see Initialize) and whenever we
// get a MappingNotify event.
func MapsGet(xu *xgbutil.XUtil) (*xproto.GetKeyboardMappingReply,
*xproto.GetModifierMappingReply) {
min, max := minMaxKeycodeGet(xu)
queryKeymap, _ := xproto.GetKeyboardMapping(xu.Conn(), nil,
min, byte(max-min+1))
newKeymap, keyErr := queryKeymap.Reply()
queryModmap, _ := xproto.GetModifierMapping(xu.Conn(), nil)
newModmap, modErr := queryModmap.Reply()
// If there are errors, we really need to panic. We just can't do
// any key binding without a mapping from the server.
if keyErr != nil {
panic(fmt.Sprintf("COULD NOT GET KEYBOARD MAPPING: %v\n"+
"THIS IS AN UNRECOVERABLE ERROR.\n",
keyErr))
}
if modErr != nil {
panic(fmt.Sprintf("COULD NOT GET MODIFIER MAPPING: %v\n"+
"THIS IS AN UNRECOVERABLE ERROR.\n",
keyErr))
}
return newKeymap, newModmap
}
示例2: PhysicalHeads
// PhyiscalHeads returns the list of heads in a physical ordering.
// Namely, left to right then top to bottom. (Defined by (X, Y).)
// Xinerama must have been initialized, otherwise the xinerama.QueryScreens
// request will panic.
// PhysicalHeads also checks to make sure each rectangle has a unique (x, y)
// tuple, so as not to return the geometry of cloned displays.
// (At present moment, xgbutil initializes Xinerama automatically during
// initial connection.)
func PhysicalHeads(xu *xgbutil.XUtil) (Heads, error) {
query, _ := xinerama.QueryScreens(xu.Conn(), nil)
xinfo, err := query.Reply()
if err != nil {
return nil, err
}
hds := make(Heads, 0)
for _, info := range xinfo.ScreenInfo {
head := xrect.New(int(info.XOrg), int(info.YOrg),
int(info.Width), int(info.Height))
// Maybe Xinerama is enabled, but we have cloned displays...
unique := true
for _, h := range hds {
if h.X() == head.X() && h.Y() == head.Y() {
unique = false
break
}
}
if unique {
hds = append(hds, head)
}
}
sort.Sort(hds)
return hds, nil
}
示例3: DesktopLayoutSet
// _NET_DESKTOP_LAYOUT set
func DesktopLayoutSet(xu *xgbutil.XUtil, orientation, columns, rows,
startingCorner uint) error {
return xprop.ChangeProp32(xu, xu.RootWin(), "_NET_DESKTOP_LAYOUT",
"CARDINAL", orientation, columns, rows,
startingCorner)
}
示例4: GrabKeyboard
// GrabKeyboard grabs the entire keyboard.
// Returns whether GrabStatus is successful and an error if one is reported by
// XGB. It is possible to not get an error and the grab to be unsuccessful.
// The purpose of 'win' is that after a grab is successful, ALL Key*Events will
// be sent to that window. Make sure you have a callback attached :-)
func GrabKeyboard(xu *xgbutil.XUtil, win xproto.Window) error {
query, _ := xproto.GrabKeyboard(xu.Conn(), nil, false, win, 0,
xproto.GrabModeAsync, xproto.GrabModeAsync)
reply, err := query.Reply()
if err != nil {
return fmt.Errorf("GrabKeyboard: Error grabbing keyboard on "+
"window '%x': %s", win, err)
}
switch reply.Status {
case xproto.GrabStatusSuccess:
// all is well
case xproto.GrabStatusAlreadyGrabbed:
return fmt.Errorf("GrabKeyboard: Could not grab keyboard. " +
"Status: AlreadyGrabbed.")
case xproto.GrabStatusInvalidTime:
return fmt.Errorf("GrabKeyboard: Could not grab keyboard. " +
"Status: InvalidTime.")
case xproto.GrabStatusNotViewable:
return fmt.Errorf("GrabKeyboard: Could not grab keyboard. " +
"Status: NotViewable.")
case xproto.GrabStatusFrozen:
return fmt.Errorf("GrabKeyboard: Could not grab keyboard. " +
"Status: Frozen.")
}
return nil
}
示例5: Ungrab
// Ungrab undoes Grab. It will handle all combinations od modifiers found
// in xevent.IgnoreMods.
func Ungrab(xu *xgbutil.XUtil, win xproto.Window,
mods uint16, key xproto.Keycode) {
for _, m := range xevent.IgnoreMods {
query, _ := xproto.UngrabKeyChecked(xu.Conn(), nil, key, win, mods|m)
query.Check()
}
}
示例6: xSource
// sendClientMessages is a goroutine that sends client messages to the root
// window. We then listen to them later as a demonstration of responding to
// X events. (They are sent with SubstructureNotify and SubstructureRedirect
// masks set. So in order to receive them, we'll have to explicitly listen
// to events of that type on the root window.)
func xSource(X *xgbutil.XUtil) {
i := 1
for {
ewmh.ClientEvent(X, X.RootWin(), "NOOP", i)
i++
time.Sleep(200 * time.Millisecond)
}
}
示例7: Grab
// Grab grabs a key with mods on a particular window.
// This will also grab all combinations of modifiers found in xevent.IgnoreMods.
func Grab(xu *xgbutil.XUtil, win xproto.Window,
mods uint16, key xproto.Keycode) {
for _, m := range xevent.IgnoreMods {
xproto.GrabKey(xu.Conn(), nil, true, win, mods|m, key,
xproto.GrabModeAsync, xproto.GrabModeAsync)
}
}
示例8: Ungrab
// Ungrab undoes Grab. It will handle all combinations of modifiers found
// in xevent.IgnoreMods.
func Ungrab(xu *xgbutil.XUtil, win xproto.Window, mods uint16,
button xproto.Button) {
for _, m := range xevent.IgnoreMods {
query, _ := xproto.UngrabButtonChecked(xu.Conn(), nil, byte(button), win, mods|m)
query.Check()
}
}
示例9: SupportedSet
// _NET_SUPPORTED set
// This will create any atoms in the argument if they don't already exist.
func SupportedSet(xu *xgbutil.XUtil, atomNames []string) error {
atoms, err := xprop.StrToAtoms(xu, atomNames)
if err != nil {
return err
}
return xprop.ChangeProp32(xu, xu.RootWin(), "_NET_SUPPORTED", "ATOM",
atoms...)
}
示例10: ShowingDesktopReq
// _NET_SHOWING_DESKTOP req
func ShowingDesktopReq(xu *xgbutil.XUtil, show bool) error {
var showInt uint
if show {
showInt = 1
} else {
showInt = 0
}
return ClientEvent(xu, xu.RootWin(), "_NET_SHOWING_DESKTOP", showInt)
}
示例11: DesktopNamesSet
// _NET_DESKTOP_NAMES set
func DesktopNamesSet(xu *xgbutil.XUtil, names []string) error {
nullterm := make([]byte, 0)
for _, name := range names {
nullterm = append(nullterm, name...)
nullterm = append(nullterm, 0)
}
return xprop.ChangeProp(xu, xu.RootWin(), 8, "_NET_DESKTOP_NAMES",
"UTF8_STRING", nullterm)
}
示例12: DesktopGeometryGet
// _NET_DESKTOP_GEOMETRY get
func DesktopGeometryGet(xu *xgbutil.XUtil) (*DesktopGeometry, error) {
geom, err := xprop.PropValNums(xprop.GetProperty(xu, xu.RootWin(),
"_NET_DESKTOP_GEOMETRY"))
if err != nil {
return nil, err
}
return &DesktopGeometry{Width: int(geom[0]), Height: int(geom[1])}, nil
}
示例13: WmHandledIconsSet
// _NET_WM_HANDLED_ICONS set
func WmHandledIconsSet(xu *xgbutil.XUtil, handle bool) error {
var handled uint
if handle {
handled = 1
} else {
handled = 0
}
return xprop.ChangeProp32(xu, xu.RootWin(), "_NET_WM_HANDLED_ICONS",
"CARDINAL", handled)
}
示例14: ShowingDesktopSet
// _NET_SHOWING_DESKTOP set
func ShowingDesktopSet(xu *xgbutil.XUtil, show bool) error {
var showInt uint
if show {
showInt = 1
} else {
showInt = 0
}
return xprop.ChangeProp32(xu, xu.RootWin(), "_NET_SHOWING_DESKTOP",
"CARDINAL", showInt)
}
示例15: DesktopViewportSet
// _NET_DESKTOP_VIEWPORT set
func DesktopViewportSet(xu *xgbutil.XUtil, viewports []DesktopViewport) error {
coords := make([]uint, len(viewports)*2)
for i, viewport := range viewports {
coords[i*2] = uint(viewport.X)
coords[i*2+1] = uint(viewport.Y)
}
return xprop.ChangeProp32(xu, xu.RootWin(), "_NET_DESKTOP_VIEWPORT",
"CARDINAL", coords...)
}