Example #1
0
// CreateChecked issues a CreateWindow checked request for Window.
// A checked request is a synchronous request. Meaning that if the request
// fails, you can get the error returned to you. However, it also forced your
// program to block for a round trip to the X server, so it is slower.
// See the docs for Create for more info.
func (w *Window) CreateChecked(parent xproto.Window, x, y, width, height,
	valueMask int, valueList ...uint32) error {

	s := w.X.Screen()
	return xproto.CreateWindowChecked(w.X.Conn(),
		s.RootDepth, w.Id, parent,
		int16(x), int16(y), uint16(width), uint16(height), 0,
		xproto.WindowClassInputOutput, s.RootVisual,
		uint32(valueMask), valueList).Check()
}
Example #2
0
func (m *TrayManager) Manage() bool {
	m.destroyOwnerWindow()

	win, _ := xwindow.Generate(TrayXU)
	m.owner = win.Id

	xproto.CreateWindowChecked(TrayXU.Conn(), 0, m.owner, TrayXU.RootWin(), 0, 0, 1, 1, 0, xproto.WindowClassInputOnly, m.visual, 0, nil)
	TrayXU.Sync()
	win.Listen(xproto.EventMaskStructureNotify)
	return m.tryOwner()
}
Example #3
0
func start_server(c *xgb.Conn, s *xproto.ScreenInfo, rl_execute_atom xproto.Atom) {
	win, err := xproto.NewWindowId(c)
	if err != nil {
		panic(err)
	}

	// Make a window which can be communicated with
	err = xproto.CreateWindowChecked(c, s.RootDepth, win, s.Root, 0, 0, 1, 1, 0, 0, 0, 0, nil).Check()
	if err != nil {
		panic(err)
	}

	err = xproto.ChangePropertyChecked(c, xproto.PropModeReplace, win,
		rl_execute_atom, xproto.AtomString, 8, xproto.PropModeReplace,
		[]byte("\x00")).Check()
	if err != nil {
		panic(err)
	}
	err = xproto.ChangeWindowAttributesChecked(c, win, xproto.CwEventMask, []uint32{xproto.EventMaskPropertyChange}).Check()
	if err != nil {
		panic(err)
	}

	get_execute_value := func() string {
		response, err := xproto.GetProperty(c, false, win, rl_execute_atom,
			xproto.GetPropertyTypeAny, 0, 1024).Reply()
		if err != nil {
			panic(err)
		}
		result := string(response.Value)
		return result
	}

	log.Print("Ready and waiting..")
	// Event loop
	for {
		reply, err := c.WaitForEvent()
		if err != nil {
			log.Panic("Error in event loop:", err)
		}

		switch event := reply.(type) {
		case xproto.PropertyNotifyEvent:
			if event.Window == win && event.Atom == rl_execute_atom {
				values := strings.Split(get_execute_value(), "\x00")
				run(values)
			}
		}
	}
}
Example #4
0
func newParent(X *xgbutil.XUtil, cid xproto.Window) (*Parent, error) {
	parent, err := xwindow.Generate(X)
	if err != nil {
		logger.Error.Printf("Could not create a parent window for client "+
			"with id '%d' because: %s", cid, err)
		logger.Error.Fatalf("In a state where no new windows can be created. " +
			"Unfortunately, we must exit.")
	}

	// clientAttrs, err := xproto.GetWindowAttributes(X.Conn(), cid).Reply()
	// if err != nil {
	// return nil, fmt.Errorf("Could not get window attributes: %s", err)
	// }

	// visual := clientAttrs.Visual
	// vdepth := getVisualDepth(X, visual)
	visual := X.Screen().RootVisual
	vdepth := X.Screen().RootDepth
	// logger.Debug.Printf("Visualid: %x, Depth: %d", visual, vdepth)
	err = xproto.CreateWindowChecked(X.Conn(),
		vdepth, parent.Id, X.RootWin(),
		0, 0, 1, 1, 0, xproto.WindowClassInputOutput, visual,
		xproto.CwEventMask,
		[]uint32{
			xproto.EventMaskSubstructureRedirect |
				xproto.EventMaskButtonPress |
				xproto.EventMaskButtonRelease |
				xproto.EventMaskFocusChange,
		}).Check()
	if err != nil {
		return nil, fmt.Errorf("Could not create window: %s", err)
	}

	err = xproto.ReparentWindowChecked(X.Conn(),
		cid, parent.Id, 0, 0).Check()
	if err != nil {
		return nil, fmt.Errorf("Could not reparent window: %s", err)
	}

	return &Parent{
		Window:      parent,
		MoveState:   &MoveState{},
		ResizeState: &ResizeState{},
		isMapped:    false,
	}, nil
}
Example #5
0
func Open(c *xgb.Conn, ctx, title, text string) (*Window, error) {
	gc, ok := ctxs[ctx]
	if !ok {
		return nil, BadContextError(ctx)
	}

	scr := xproto.Setup(c).DefaultScreen(c)
	wdwid, err := xproto.NewWindowId(c)
	if err != nil {
		return nil, err
	}

	lines := cutLines(c, gc.width-2*gc.border, gc.font, text)
	height := uint32(len(lines)) * gc.fontHeight

	var mask uint32 = xproto.CwBackPixel | xproto.CwOverrideRedirect | xproto.CwEventMask
	values := make([]uint32, 3)
	values[0] = scr.WhitePixel
	values[1] = 1
	values[2] = xproto.EventMaskExposure
	err = xproto.CreateWindowChecked(c, xproto.WindowClassCopyFromParent, wdwid, scr.Root,
		0, 0, uint16(gc.width), uint16(height+2*gc.border), 1,
		xproto.WindowClassInputOutput, scr.RootVisual,
		mask, values).Check()
	if err != nil {
		return nil, err
	}
	xproto.ChangeProperty(c, xproto.PropModeReplace, wdwid,
		xproto.AtomWmName, xproto.AtomString,
		8, uint32(len(title)), []byte(title))

	var wdw Window
	wdw.id = wdwid
	wdw.conn = c
	wdw.lines = lines
	wdw.gc = gc
	wdw.geom = types.Geometry{0, 0, int32(gc.width), int32(height + 2*gc.border)}
	return &wdw, nil
}
Example #6
0
func initDesktop(xScreen *xp.ScreenInfo) {
	xFont, err := xp.NewFontId(xConn)
	if err != nil {
		log.Fatal(err)
	}
	xCursor, err := xp.NewCursorId(xConn)
	if err != nil {
		log.Fatal(err)
	}
	err = xp.OpenFontChecked(xConn, xFont, uint16(len("cursor")), "cursor").Check()
	if err != nil {
		log.Fatal(err)
	}
	const xcLeftPtr = 68 // XC_left_ptr from cursorfont.h.
	err = xp.CreateGlyphCursorChecked(
		xConn, xCursor, xFont, xFont, xcLeftPtr, xcLeftPtr+1,
		0xffff, 0xffff, 0xffff, 0, 0, 0).Check()
	if err != nil {
		log.Fatal(err)
	}
	err = xp.CloseFontChecked(xConn, xFont).Check()
	if err != nil {
		log.Fatal(err)
	}

	desktopXWin, err = xp.NewWindowId(xConn)
	if err != nil {
		log.Fatal(err)
	}
	desktopXGC, err = xp.NewGcontextId(xConn)
	if err != nil {
		log.Fatal(err)
	}
	desktopWidth = xScreen.WidthInPixels
	desktopHeight = xScreen.HeightInPixels

	if err := xp.CreateWindowChecked(
		xConn, xScreen.RootDepth, desktopXWin, xScreen.Root,
		0, 0, desktopWidth, desktopHeight, 0,
		xp.WindowClassInputOutput,
		xScreen.RootVisual,
		xp.CwOverrideRedirect|xp.CwEventMask,
		[]uint32{
			1,
			xp.EventMaskExposure,
		},
	).Check(); err != nil {
		log.Fatal(err)
	}

	if len(xSettings) != 0 {
		initXSettings()
	}

	if err := xp.ConfigureWindowChecked(
		xConn,
		desktopXWin,
		xp.ConfigWindowStackMode,
		[]uint32{
			xp.StackModeBelow,
		},
	).Check(); err != nil {
		log.Fatal(err)
	}

	if err := xp.ChangeWindowAttributesChecked(
		xConn,
		desktopXWin,
		xp.CwBackPixel|xp.CwCursor,
		[]uint32{
			xScreen.BlackPixel,
			uint32(xCursor),
		},
	).Check(); err != nil {
		log.Fatal(err)
	}

	if err := xp.CreateGCChecked(
		xConn,
		desktopXGC,
		xp.Drawable(xScreen.Root),
		0,
		nil,
	).Check(); err != nil {
		log.Fatal(err)
	}

	if err := xp.MapWindowChecked(xConn, desktopXWin).Check(); err != nil {
		log.Fatal(err)
	}
}