-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates #47
- Loading branch information
Showing
12 changed files
with
1,394 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Occamy GUI | ||
|
||
This is a minimum example of building an occamy client. | ||
|
||
It is based on the [bring](https://github.com/deluan/bring) implementation of the Guacamole protocol. | ||
|
||
Note that `bring` is a software renderer that does not utilize Gio's GPU backend. | ||
Hence there is a lot of improvements for building this application. | ||
|
||
Later coding will revise the code into a gio accelerated rendering. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2021 Changkun Ou. All rights reserved. | ||
// Use of this source code is governed by a MIT | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"image" | ||
"log" | ||
"os" | ||
|
||
"changkun.de/x/occamy/internal/guac" | ||
|
||
"gioui.org/app" | ||
"gioui.org/io/event" | ||
"gioui.org/io/key" | ||
"gioui.org/io/pointer" | ||
"gioui.org/io/system" | ||
"gioui.org/op" | ||
"gioui.org/op/paint" | ||
"gioui.org/unit" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 3 { | ||
log.Fatal("Usage: occamy-gui <vnc|rdp> host:port") | ||
return | ||
} | ||
|
||
a, err := NewApp(os.Args[1], os.Args[2]) | ||
if err != nil { | ||
log.Fatalf("cannot create Occamy client: %v", err) | ||
} | ||
go a.Run() | ||
app.Main() | ||
} | ||
|
||
type App struct { | ||
client *guac.Client | ||
win *app.Window | ||
} | ||
|
||
func NewApp(protocol, addr string) (a *App, err error) { | ||
log.SetPrefix("occamy: ") | ||
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile) | ||
|
||
a = &App{} | ||
a.win = app.NewWindow(app.Title("Occamy GUI Client")) | ||
a.client, err = guac.NewClient("0.0.0.0:5636", map[string]string{ | ||
"host": addr, | ||
"protocol": protocol, | ||
"username": "", | ||
"password": "vncpassword", | ||
}, a.win) | ||
if err != nil { | ||
return nil, err | ||
} | ||
w, h := 1280*2, 1024*2 | ||
a.win.Option( | ||
app.Size(unit.Px(float32(w)), unit.Px(float32(h))), | ||
app.MaxSize(unit.Px(float32(w)), unit.Px(float32(h))), | ||
app.MinSize(unit.Px(float32(w)), unit.Px(float32(h))), | ||
) | ||
return a, nil | ||
} | ||
|
||
func (a *App) Run() { | ||
for e := range a.win.Events() { | ||
switch e := e.(type) { | ||
case system.DestroyEvent: | ||
log.Println(e.Err) | ||
os.Exit(0) | ||
case system.FrameEvent: | ||
ops := &op.Ops{} | ||
a.updateScreen(ops, e.Queue) | ||
e.Frame(ops) | ||
case pointer.Event: | ||
if err := a.client.SendMouse( | ||
image.Point{X: int(e.Position.X), Y: int(e.Position.Y)}, | ||
guac.MouseToGioButton[e.Buttons]); err != nil { | ||
log.Println(err) | ||
} | ||
a.win.Invalidate() | ||
case key.Event: | ||
log.Printf("%+v, %+v", e.Name, e.Modifiers) | ||
|
||
// TODO: keyboard seems problematic, yet. | ||
// See https://todo.sr.ht/~eliasnaur/gio/319 | ||
// var keycode guac.KeyCode | ||
// switch { | ||
// case e.Modifiers.Contain(key.ModCtrl): | ||
// keycode = guac.KeyCode(guac.KeyLeftControl) | ||
// case e.Modifiers.Contain(key.ModCommand): | ||
// keycode = guac.KeyCode(guac.KeyLeftControl) | ||
// case e.Modifiers.Contain(key.ModShift): | ||
// keycode = guac.KeyCode(guac.KeyLeftShift) | ||
// case e.Modifiers.Contain(key.ModAlt): | ||
// keycode = guac.KeyCode(guac.KeyLeftAlt) | ||
// case e.Modifiers.Contain(key.ModSuper): | ||
// keycode = guac.KeyCode(guac.KeySuper) | ||
// } | ||
// err := a.client.SendKey(keycode, e.State == key.Press) | ||
// if err != nil { | ||
// log.Println(err) | ||
// } | ||
} | ||
} | ||
} | ||
|
||
func (a *App) updateScreen(ops *op.Ops, q event.Queue) { | ||
img, _ := a.client.Screen() | ||
paint.NewImageOp(img).Add(ops) | ||
paint.PaintOp{}.Add(ops) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.