Exemple #1
0
// WMGracefulClose will do all the necessary setup to implement the
// WM_DELETE_WINDOW protocol. This will prevent well-behaving window managers
// from killing your client whenever one of your windows is closed. (Killing
// a client is bad because it will destroy your X connection and any other
// clients you have open.)
// You must provide a callback function that is called when the window manager
// asks you to close your window. (You may provide some means of confirmation
// to the user, i.e., "Do you really want to quit?", but you should probably
// just wrap things up and call DestroyWindow.)
func (w *Window) WMGracefulClose(cb func(w *Window)) {
	// Get the current protocols so we don't overwrite anything.
	prots, _ := icccm.WmProtocolsGet(w.X, w.Id)

	// If WM_DELETE_WINDOW isn't here, add it. Otherwise, move on.
	wmdelete := false
	for _, prot := range prots {
		if prot == "WM_DELETE_WINDOW" {
			wmdelete = true
			break
		}
	}
	if !wmdelete {
		icccm.WmProtocolsSet(w.X, w.Id, append(prots, "WM_DELETE_WINDOW"))
	}

	// Attach a ClientMessage event handler. It will determine whether the
	// ClientMessage is a 'close' request, and if so, run the callback 'cb'
	// provided.
	xevent.ClientMessageFun(
		func(X *xgbutil.XUtil, ev xevent.ClientMessageEvent) {
			if icccm.IsDeleteProtocol(X, ev) {
				cb(w)
			}
		}).Connect(w.X, w.Id)
}
Exemple #2
0
func main() {
	X, _ := xgbutil.NewConn()

	active, err := ewmh.ActiveWindowGet(X)

	wmName, err := icccm.WmNameGet(X, active)
	showTest("WM_NAME get", wmName, err)

	err = icccm.WmNameSet(X, active, "hooblah")
	wmName, _ = icccm.WmNameGet(X, active)
	showTest("WM_NAME set", wmName, err)

	wmNormHints, err := icccm.WmNormalHintsGet(X, active)
	showTest("WM_NORMAL_HINTS get", wmNormHints, err)

	wmNormHints.Width += 5
	err = icccm.WmNormalHintsSet(X, active, wmNormHints)
	showTest("WM_NORMAL_HINTS set", wmNormHints, err)

	wmHints, err := icccm.WmHintsGet(X, active)
	showTest("WM_HINTS get", wmHints, err)

	wmHints.InitialState = icccm.StateNormal
	err = icccm.WmHintsSet(X, active, wmHints)
	showTest("WM_NORMAL_HINTS set", wmHints, err)

	wmClass, err := icccm.WmClassGet(X, active)
	showTest("WM_CLASS get", wmClass, err)

	wmClass.Instance = "hoopdy hoop"
	err = icccm.WmClassSet(X, active, wmClass)
	showTest("WM_CLASS set", wmClass, err)

	wmTrans, err := icccm.WmTransientForGet(X, active)
	showTest("WM_TRANSIENT_FOR get", wmTrans, err)

	wmProts, err := icccm.WmProtocolsGet(X, active)
	showTest("WM_PROTOCOLS get", wmProts, err)

	wmClient, err := icccm.WmClientMachineGet(X, active)
	showTest("WM_CLIENT_MACHINE get", wmClient, err)

	err = icccm.WmClientMachineSet(X, active, "Leopard")
	wmClient, _ = icccm.WmClientMachineGet(X, active)
	showTest("WM_CLIENT_MACHINE set", wmClient, err)

	wmState, err := icccm.WmStateGet(X, active)
	showTest("WM_STATE get", wmState, err)

	wmState.Icon = xproto.Window(8365538)
	wmState.State = icccm.StateNormal
	err = icccm.WmStateSet(X, active, wmState)
	wmState, _ = icccm.WmStateGet(X, active)
	showTest("WM_STATE set", wmState, err)
}
Exemple #3
0
func (c *client) fetchXProperties() {
	var err error

	c.hints, err = icccm.WmHintsGet(c.X, c.Id())
	if err != nil {
		logger.Warning.Println(err)
		logger.Message.Printf("Using reasonable defaults for WM_HINTS for %X",
			c.Id())
		c.hints = &icccm.Hints{
			Flags:        icccm.HintInput | icccm.HintState,
			Input:        1,
			InitialState: icccm.StateNormal,
		}
	}

	c.nhints, err = icccm.WmNormalHintsGet(c.X, c.Id())
	if err != nil {
		logger.Warning.Println(err)
		logger.Message.Printf("Using reasonable defaults for WM_NORMAL_HINTS "+
			"for %X", c.Id())
		c.nhints = &icccm.NormalHints{}
	}

	c.protocols, err = icccm.WmProtocolsGet(c.X, c.Id())
	if err != nil {
		logger.Warning.Printf(
			"Window %X does not have WM_PROTOCOLS set.", c.Id())
	}

	c.winTypes, err = ewmh.WmWindowTypeGet(c.X, c.Id())
	if err != nil {
		logger.Warning.Printf("Could not find window type for window %X, "+
			"using 'normal'.", c.Id())
		c.winTypes = []string{"_NET_WM_WINDOW_TYPE_NORMAL"}
	}

	trans, _ := icccm.WmTransientForGet(c.X, c.Id())
	if trans == 0 {
		for _, c2 := range wingo.clients {
			if c2.transient(c) {
				c.transientFor = c2
				break
			}
		}
	} else if transCli := wingo.findManagedClient(trans); transCli != nil {
		c.transientFor = transCli
	}
}
Exemple #4
0
// WMTakeFocus will do all the necessary setup to support the WM_TAKE_FOCUS
// protocol using the "LocallyActive" input model described in Section 4.1.7
// of the ICCCM. Namely, listening to ClientMessage events and running the
// callback function provided when a WM_TAKE_FOCUS ClientMessage has been
// received.
//
// Typically, the callback function should include a call to SetInputFocus
// with the "Parent" InputFocus type, the sub-window id of the window that
// should have focus, and the 'tstamp' timestamp.
func (w *Window) WMTakeFocus(cb func(w *Window, tstamp xproto.Timestamp)) {
	// Make sure the Input flag is set to true in WM_HINTS. We first
	// must retrieve the current WM_HINTS, so we don't overwrite the flags.
	curFlags := 0
	if hints, err := icccm.WmHintsGet(w.X, w.Id); err == nil {
		curFlags = hints.Flags
	}
	icccm.WmHintsSet(w.X, w.Id, &icccm.Hints{
		Flags: curFlags | icccm.HintInput,
		Input: 1,
	})

	// Get the current protocols so we don't overwrite anything.
	prots, _ := icccm.WmProtocolsGet(w.X, w.Id)

	// If WM_TAKE_FOCUS isn't here, add it. Otherwise, move on.
	wmfocus := false
	for _, prot := range prots {
		if prot == "WM_TAKE_FOCUS" {
			wmfocus = true
			break
		}
	}
	if !wmfocus {
		icccm.WmProtocolsSet(w.X, w.Id, append(prots, "WM_TAKE_FOCUS"))
	}

	// Attach a ClientMessage event handler. It will determine whether the
	// ClientMessage is a 'focus' request, and if so, run the callback 'cb'
	// provided.
	xevent.ClientMessageFun(
		func(X *xgbutil.XUtil, ev xevent.ClientMessageEvent) {
			if icccm.IsFocusProtocol(X, ev) {
				cb(w, xproto.Timestamp(ev.Data.Data32[1]))
			}
		}).Connect(w.X, w.Id)
}
Exemple #5
0
func (c *Client) fetchXProperties() {
	var err error

	c.hints, err = icccm.WmHintsGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Println(err)
		logger.Message.Printf("Using reasonable defaults for WM_HINTS for %X",
			c.Id())
		c.hints = &icccm.Hints{
			Flags:        icccm.HintInput | icccm.HintState,
			Input:        1,
			InitialState: icccm.StateNormal,
		}
	}

	c.nhints, err = icccm.WmNormalHintsGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Println(err)
		logger.Message.Printf("Using reasonable defaults for WM_NORMAL_HINTS "+
			"for %X", c.Id())
		c.nhints = &icccm.NormalHints{}
	}

	c.protocols, err = icccm.WmProtocolsGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Printf(
			"Window %X does not have WM_PROTOCOLS set.", c.Id())
	}

	c.winTypes, err = ewmh.WmWindowTypeGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Printf("Could not find window type for window %X, "+
			"using 'normal'.", c.Id())
		c.winTypes = []string{"_NET_WM_WINDOW_TYPE_NORMAL"}
	}

	c.winStates, err = ewmh.WmStateGet(wm.X, c.Id())
	if err != nil {
		c.winStates = []string{}
		ewmh.WmStateSet(wm.X, c.Id(), c.winStates)
	}

	c.class, err = icccm.WmClassGet(wm.X, c.Id())
	if err != nil {
		logger.Warning.Printf("Could not find window class for window %X: %s",
			c.Id(), err)
		c.class = &icccm.WmClass{
			Instance: "",
			Class:    "",
		}
	}

	trans, _ := icccm.WmTransientForGet(wm.X, c.Id())
	if trans == 0 {
		for _, c2_ := range wm.Clients {
			c2 := c2_.(*Client)
			if c2.transient(c) {
				c.transientFor = c2
				break
			}
		}
	} else if transCli := wm.FindManagedClient(trans); transCli != nil {
		c.transientFor = transCli.(*Client)
	}

	tmp, err := xprop.PropValNum(
		xprop.GetProperty(wm.X, c.Id(), "_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED"))
	if err == nil {
		c.gtkMaximizeNada = (tmp == 1)
	} else {
		c.gtkMaximizeNada = false
	}

	c.setShaped()
}