{"id":20709009,"url":"https://github.com/difrex/gosway","last_synced_at":"2025-04-23T02:52:12.801Z","repository":{"id":43379987,"uuid":"179972995","full_name":"Difrex/gosway","owner":"Difrex","description":"Golang Sway IPC bindings","archived":false,"fork":false,"pushed_at":"2024-10-13T18:43:47.000Z","size":63,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T21:22:30.367Z","etag":null,"topics":["golang","ipc","sway","tiling"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Difrex.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-07T13:51:40.000Z","updated_at":"2025-01-29T02:39:02.000Z","dependencies_parsed_at":"2024-03-12T15:53:28.968Z","dependency_job_id":"1f1da03e-b562-4b71-881c-90534df9704e","html_url":"https://github.com/Difrex/gosway","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Difrex%2Fgosway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Difrex%2Fgosway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Difrex%2Fgosway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Difrex%2Fgosway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Difrex","download_url":"https://codeload.github.com/Difrex/gosway/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250360249,"owners_count":21417718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","ipc","sway","tiling"],"created_at":"2024-11-17T01:34:31.448Z","updated_at":"2025-04-23T02:52:12.756Z","avatar_url":"https://github.com/Difrex.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"* GoSway\n\nGolang [[https://github.com/swaywm/sway][Sway]] IPC bindings.\n\n* Install\n\n#+begin_src\ngo get github.com/Difrex/gosway/ipc\n#+end_src\n\n* Usage\n\nInitialize an new connection to the Sway socket\n#+begin_src go\nimport (\n\t\"github.com/Difrex/gosway/ipc\"\n)\n\nsc, err := ipc.NewSwayConnection()\nif err != nil {\n    panic(err)\n}\n#+end_src\n\n*** Workspaces\n\nWorkspaces list\n#+begin_src go\nws, err := sc.GetWorkspaces()\nif err != nil {\n    panic(err)\n}\n\nfor _, workspace := range ws {\n    fmt.Println(workspace.Name)\n}\n#+end_src\n\nGet focused workspace\n#+begin_src go\nws, err := sc.GetFocusedWorkspace()\nif err != nil {\n    panic(err)\n}\n#+end_src\n\nGet focused workspace windows\n#+begin_src go\nwindows, err := sc.GetFocusedWorkspaceWindows()\nif err != nil {\n    panic(err)\n}\nfor _, window := range windows {\n    fmt.Println(window.Name)\n}\n#+end_src\n\n* Events subscribe\n\nYou needs a connection for sending command to the Sway and another one for events listener.\n\n#+begin_src go\ncommandConn, err := ipc.NewSwayConnection()\nif err != nil {\n    panic(err)\n}\n\nsubCon, err := ipc.NewSwayConnection()\nif err != nil {\n    panic(err)\n}\n\n// Subscribe only to the window related events\n_, err = subCon.SendCommand(ipc.IPC_SUBSCRIBE, `[\"window\"]`)\nif err != nil {\n\tpanic(err)\n}\n\n// Listen for the events\ns := subCon.Subscribe()\ndefer s.Close()\n\nfor {\n    select {\n\tcase event := \u003c-s.Events:\n\t    if event.Change == \"new\" {\n            commandConn.RunSwayCommand(fmt.Sprintf(\"[con_id=%d] split h\", event.Container.ID))\n            commandConn.RunSwayCommand(fmt.Sprintf(\"[con_id=%d] move down\", event.Container.ID))\n        }\n    case err := \u003c-s.Errors:\n\t\tfmt.Println(\"Error:\", err)\n\t\tbreak\n\t}\n}\n#+end_src\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdifrex%2Fgosway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdifrex%2Fgosway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdifrex%2Fgosway/lists"}