Пример #1
0
func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
	width, height := 1024, 768
	if opts != nil {
		if opts.Width > 0 {
			width = opts.Width
		}
		if opts.Height > 0 {
			height = opts.Height
		}
	}

	id := newWindow(int32(width), int32(height))
	w := &windowImpl{
		s:           s,
		id:          id,
		pump:        pump.Make(),
		publish:     make(chan struct{}),
		publishDone: make(chan screen.PublishResult),
		drawDone:    make(chan struct{}),
	}

	s.mu.Lock()
	s.windows[id] = w
	s.mu.Unlock()

	showWindow(w)

	return w, nil
}
Пример #2
0
func newWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
	hwnd, err := createWindow()
	if err != nil {
		return nil, err
	}

	w := &windowImpl{
		hwnd: hwnd,
		pump: pump.Make(),
	}

	windowsMu.Lock()
	windows[hwnd] = w
	windowsMu.Unlock()

	// Send a fake size event.
	// Windows won't generate the WM_WINDOWPOSCHANGED
	// we trigger a resize on for the initial size, so we have to do
	// it ourselves. The example/basic program assumes it will
	// receive a size.Event for the initial window size that isn't 0x0.
	var r _RECT
	// TODO(andlabs) error check
	_GetClientRect(w.hwnd, &r)
	sendSizeEvent(w.hwnd, &r)

	return w, nil
}
Пример #3
0
func newWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
	var hwnd C.HWND

	hr := C.createWindow(&hwnd)
	if hr != C.S_OK {
		return nil, winerror("error creating window", hr)
	}
	return &window{
		hwnd: hwnd,
		pump: pump.Make(),
	}, nil
}
Пример #4
0
func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
	w := &windowImpl{
		pump: pump.Make(),
	}

	var err error
	w.hwnd, err = win32.NewWindow(opts)
	if err != nil {
		return nil, err
	}

	s.mu.Lock()
	s.windows[w.hwnd] = w
	s.mu.Unlock()

	win32.Show(w.hwnd)
	return w, nil
}
Пример #5
0
func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
	// TODO: look at opts.
	const width, height = 1024, 768

	id := C.newWindow(width, height)
	w := &windowImpl{
		s:        s,
		id:       uintptr(id),
		pump:     pump.Make(),
		endPaint: make(chan paint.Event, 1),
		draw:     make(chan struct{}),
		drawDone: make(chan struct{}),
	}

	s.mu.Lock()
	s.windows[uintptr(id)] = w
	s.mu.Unlock()

	go w.drawLoop(uintptr(C.showWindow(id)))

	return w, nil
}
Пример #6
0
func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
	// TODO: look at opts.
	const width, height = 1024, 768

	id := newWindow(width, height)
	w := &windowImpl{
		s:        s,
		id:       id,
		pump:     pump.Make(),
		publish:  make(chan struct{}, 1),
		draw:     make(chan struct{}),
		drawDone: make(chan struct{}),
	}

	s.mu.Lock()
	s.windows[id] = w
	s.mu.Unlock()

	showWindow(w)
	go drawLoop(w)

	return w, nil
}
Пример #7
0
func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) {
	// TODO: look at opts.
	const width, height = 1024, 768

	xw, err := xproto.NewWindowId(s.xc)
	if err != nil {
		return nil, fmt.Errorf("x11driver: xproto.NewWindowId failed: %v", err)
	}
	xg, err := xproto.NewGcontextId(s.xc)
	if err != nil {
		return nil, fmt.Errorf("x11driver: xproto.NewGcontextId failed: %v", err)
	}
	xp, err := render.NewPictureId(s.xc)
	if err != nil {
		return nil, fmt.Errorf("x11driver: render.NewPictureId failed: %v", err)
	}
	pictformat := render.Pictformat(0)
	switch s.xsi.RootDepth {
	default:
		return nil, fmt.Errorf("x11driver: unsupported root depth %d", s.xsi.RootDepth)
	case 24:
		pictformat = s.pictformat24
	case 32:
		pictformat = s.pictformat32
	}

	w := &windowImpl{
		s:       s,
		xw:      xw,
		xg:      xg,
		xp:      xp,
		pump:    pump.Make(),
		xevents: make(chan xgb.Event),
	}

	s.mu.Lock()
	s.windows[xw] = w
	s.mu.Unlock()

	xproto.CreateWindow(s.xc, s.xsi.RootDepth, xw, s.xsi.Root,
		0, 0, width, height, 0,
		xproto.WindowClassInputOutput, s.xsi.RootVisual,
		xproto.CwEventMask,
		[]uint32{0 |
			xproto.EventMaskKeyPress |
			xproto.EventMaskKeyRelease |
			xproto.EventMaskButtonPress |
			xproto.EventMaskButtonRelease |
			xproto.EventMaskPointerMotion |
			xproto.EventMaskExposure |
			xproto.EventMaskStructureNotify |
			xproto.EventMaskFocusChange,
		},
	)
	s.setProperty(xw, s.atomWMProtocols, s.atomWMDeleteWindow, s.atomWMTakeFocus)
	xproto.CreateGC(s.xc, xg, xproto.Drawable(xw), 0, nil)
	render.CreatePicture(s.xc, xp, xproto.Drawable(xw), pictformat, 0, nil)
	xproto.MapWindow(s.xc, xw)

	return w, nil
}