├── .builds ├── alpine.yml ├── archlinux.yml └── freebsd.yml ├── .editorconfig ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ ├── enhancement.md │ └── i3_compat.md ├── .gitignore ├── .mailmap ├── CONTRIBUTING.md ├── LICENSE ├── README.ar.md ├── README.cs.md ├── README.de.md ├── README.dk.md ├── README.es.md ├── README.fr.md ├── README.ge.md ├── README.gr.md ├── README.hi.md ├── README.hu.md ├── README.ir.md ├── README.it.md ├── README.ja.md ├── README.ko.md ├── README.md ├── README.nl.md ├── README.no.md ├── README.pl.md ├── README.pt.md ├── README.ro.md ├── README.ru.md ├── README.sv.md ├── README.tr.md ├── README.uk.md ├── README.zh-CN.md ├── README.zh-TW.md ├── assets ├── LICENSE ├── Sway_Logo+Text_Ver1.svg ├── Sway_Logo+Text_Ver1_1500x716.png ├── Sway_Logo+Text_Ver2.png ├── Sway_Logo+Text_Ver2.svg ├── Sway_Logo+Text_Ver3.png ├── Sway_Logo+Text_Ver3.svg ├── Sway_Logo+Text_Ver4.png ├── Sway_Logo+Text_Ver4.svg ├── Sway_Tree.png ├── Sway_Tree.svg ├── Sway_Tree_1000x934.png ├── Sway_Wallpaper_Blue_1136x640.png ├── Sway_Wallpaper_Blue_1136x640_Portrait.png ├── Sway_Wallpaper_Blue_1366x768.png ├── Sway_Wallpaper_Blue_1920x1080.png ├── Sway_Wallpaper_Blue_2048x1536.png ├── Sway_Wallpaper_Blue_2048x1536_Portrait.png ├── Sway_Wallpaper_Blue_768x1024.png └── Sway_Wallpaper_Blue_768x1024_Portrait.png ├── client ├── meson.build └── pool-buffer.c ├── common ├── cairo.c ├── gesture.c ├── ipc-client.c ├── list.c ├── log.c ├── loop.c ├── meson.build ├── pango.c ├── stringop.c └── util.c ├── completions ├── bash │ ├── sway │ ├── swaybar │ └── swaymsg ├── fish │ ├── sway.fish │ ├── swaymsg.fish │ └── swaynag.fish ├── meson.build └── zsh │ ├── _sway │ ├── _swaybar │ └── _swaymsg ├── config.in ├── include ├── cairo_util.h ├── gesture.h ├── ipc-client.h ├── ipc.h ├── list.h ├── log.h ├── loop.h ├── meson.build ├── pango.h ├── pool-buffer.h ├── stringop.h ├── sway │ ├── commands.h │ ├── config.h │ ├── criteria.h │ ├── decoration.h │ ├── desktop │ │ ├── idle_inhibit_v1.h │ │ ├── launcher.h │ │ └── transaction.h │ ├── input │ │ ├── cursor.h │ │ ├── input-manager.h │ │ ├── keyboard.h │ │ ├── libinput.h │ │ ├── seat.h │ │ ├── switch.h │ │ ├── tablet.h │ │ ├── text_input.h │ │ └── text_input_popup.h │ ├── ipc-json.h │ ├── ipc-server.h │ ├── layers.h │ ├── lock.h │ ├── output.h │ ├── scene_descriptor.h │ ├── server.h │ ├── sway_text_node.h │ ├── swaynag.h │ ├── tree │ │ ├── arrange.h │ │ ├── container.h │ │ ├── node.h │ │ ├── root.h │ │ ├── view.h │ │ └── workspace.h │ ├── xdg_decoration.h │ └── xwayland.h ├── swaybar │ ├── bar.h │ ├── config.h │ ├── i3bar.h │ ├── image.h │ ├── input.h │ ├── ipc.h │ ├── render.h │ ├── status_line.h │ └── tray │ │ ├── host.h │ │ ├── icon.h │ │ ├── item.h │ │ ├── tray.h │ │ └── watcher.h ├── swaynag │ ├── config.h │ ├── render.h │ ├── swaynag.h │ └── types.h └── util.h ├── meson.build ├── meson_options.txt ├── protocols ├── idle.xml ├── meson.build ├── wlr-layer-shell-unstable-v1.xml └── wlr-output-power-management-unstable-v1.xml ├── release.sh ├── sway.desktop ├── sway ├── commands.c ├── commands │ ├── allow_tearing.c │ ├── assign.c │ ├── bar.c │ ├── bar │ │ ├── bind.c │ │ ├── binding_mode_indicator.c │ │ ├── colors.c │ │ ├── font.c │ │ ├── gaps.c │ │ ├── height.c │ │ ├── hidden_state.c │ │ ├── icon_theme.c │ │ ├── id.c │ │ ├── mode.c │ │ ├── modifier.c │ │ ├── output.c │ │ ├── pango_markup.c │ │ ├── position.c │ │ ├── separator_symbol.c │ │ ├── status_command.c │ │ ├── status_edge_padding.c │ │ ├── status_padding.c │ │ ├── strip_workspace_name.c │ │ ├── strip_workspace_numbers.c │ │ ├── swaybar_command.c │ │ ├── tray_bind.c │ │ ├── tray_output.c │ │ ├── tray_padding.c │ │ ├── workspace_buttons.c │ │ ├── workspace_min_width.c │ │ └── wrap_scroll.c │ ├── bind.c │ ├── border.c │ ├── client.c │ ├── create_output.c │ ├── default_border.c │ ├── default_floating_border.c │ ├── default_orientation.c │ ├── exec.c │ ├── exec_always.c │ ├── exit.c │ ├── floating.c │ ├── floating_minmax_size.c │ ├── floating_modifier.c │ ├── focus.c │ ├── focus_follows_mouse.c │ ├── focus_on_window_activation.c │ ├── focus_wrapping.c │ ├── font.c │ ├── for_window.c │ ├── force_display_urgency_hint.c │ ├── force_focus_wrapping.c │ ├── fullscreen.c │ ├── gaps.c │ ├── gesture.c │ ├── hide_edge_borders.c │ ├── include.c │ ├── inhibit_idle.c │ ├── input.c │ ├── input │ │ ├── accel_profile.c │ │ ├── calibration_matrix.c │ │ ├── click_method.c │ │ ├── clickfinger_button_map.c │ │ ├── drag.c │ │ ├── drag_lock.c │ │ ├── dwt.c │ │ ├── dwtp.c │ │ ├── events.c │ │ ├── left_handed.c │ │ ├── map_from_region.c │ │ ├── map_to_output.c │ │ ├── map_to_region.c │ │ ├── middle_emulation.c │ │ ├── natural_scroll.c │ │ ├── pointer_accel.c │ │ ├── repeat_delay.c │ │ ├── repeat_rate.c │ │ ├── rotation_angle.c │ │ ├── scroll_button.c │ │ ├── scroll_button_lock.c │ │ ├── scroll_factor.c │ │ ├── scroll_method.c │ │ ├── tap.c │ │ ├── tap_button_map.c │ │ ├── tool_mode.c │ │ ├── xkb_capslock.c │ │ ├── xkb_file.c │ │ ├── xkb_layout.c │ │ ├── xkb_model.c │ │ ├── xkb_numlock.c │ │ ├── xkb_options.c │ │ ├── xkb_rules.c │ │ ├── xkb_switch_layout.c │ │ └── xkb_variant.c │ ├── kill.c │ ├── layout.c │ ├── mark.c │ ├── max_render_time.c │ ├── mode.c │ ├── mouse_warping.c │ ├── move.c │ ├── new_float.c │ ├── new_window.c │ ├── no_focus.c │ ├── nop.c │ ├── opacity.c │ ├── output.c │ ├── output │ │ ├── adaptive_sync.c │ │ ├── allow_tearing.c │ │ ├── background.c │ │ ├── color_profile.c │ │ ├── disable.c │ │ ├── dpms.c │ │ ├── enable.c │ │ ├── max_render_time.c │ │ ├── mode.c │ │ ├── position.c │ │ ├── power.c │ │ ├── render_bit_depth.c │ │ ├── scale.c │ │ ├── scale_filter.c │ │ ├── subpixel.c │ │ ├── toggle.c │ │ ├── transform.c │ │ └── unplug.c │ ├── popup_during_fullscreen.c │ ├── primary_selection.c │ ├── reload.c │ ├── rename.c │ ├── resize.c │ ├── scratchpad.c │ ├── seat.c │ ├── seat │ │ ├── attach.c │ │ ├── cursor.c │ │ ├── fallback.c │ │ ├── hide_cursor.c │ │ ├── idle.c │ │ ├── keyboard_grouping.c │ │ ├── pointer_constraint.c │ │ ├── shortcuts_inhibitor.c │ │ └── xcursor_theme.c │ ├── set.c │ ├── shortcuts_inhibitor.c │ ├── show_marks.c │ ├── smart_borders.c │ ├── smart_gaps.c │ ├── split.c │ ├── sticky.c │ ├── swap.c │ ├── swaybg_command.c │ ├── swaynag_command.c │ ├── tiling_drag.c │ ├── tiling_drag_threshold.c │ ├── title_align.c │ ├── title_format.c │ ├── titlebar_border_thickness.c │ ├── titlebar_padding.c │ ├── unmark.c │ ├── urgent.c │ ├── workspace.c │ ├── workspace_layout.c │ ├── ws_auto_back_and_forth.c │ └── xwayland.c ├── config.c ├── config │ ├── bar.c │ ├── input.c │ ├── output.c │ └── seat.c ├── criteria.c ├── decoration.c ├── desktop │ ├── idle_inhibit_v1.c │ ├── launcher.c │ ├── layer_shell.c │ ├── output.c │ ├── tearing.c │ ├── transaction.c │ ├── xdg_shell.c │ └── xwayland.c ├── input │ ├── cursor.c │ ├── input-manager.c │ ├── keyboard.c │ ├── libinput.c │ ├── seat.c │ ├── seatop_default.c │ ├── seatop_down.c │ ├── seatop_move_floating.c │ ├── seatop_move_tiling.c │ ├── seatop_resize_floating.c │ ├── seatop_resize_tiling.c │ ├── switch.c │ ├── tablet.c │ └── text_input.c ├── ipc-json.c ├── ipc-server.c ├── lock.c ├── main.c ├── meson.build ├── realtime.c ├── scene_descriptor.c ├── server.c ├── sway-bar.5.scd ├── sway-input.5.scd ├── sway-ipc.7.scd ├── sway-output.5.scd ├── sway.1.scd ├── sway.5.scd ├── sway_text_node.c ├── swaynag.c ├── tree │ ├── arrange.c │ ├── container.c │ ├── node.c │ ├── output.c │ ├── root.c │ ├── view.c │ └── workspace.c ├── xdg_activation_v1.c └── xdg_decoration.c ├── swaybar ├── bar.c ├── config.c ├── i3bar.c ├── image.c ├── input.c ├── ipc.c ├── main.c ├── meson.build ├── render.c ├── status_line.c ├── swaybar-protocol.7.scd └── tray │ ├── host.c │ ├── icon.c │ ├── item.c │ ├── tray.c │ └── watcher.c ├── swaymsg ├── main.c ├── meson.build └── swaymsg.1.scd └── swaynag ├── config.c ├── main.c ├── meson.build ├── render.c ├── swaynag.1.scd ├── swaynag.5.scd ├── swaynag.c └── types.c /.builds/alpine.yml: -------------------------------------------------------------------------------- 1 | image: alpine/edge 2 | packages: 3 | - cairo-dev 4 | - eudev-dev 5 | - gdk-pixbuf-dev 6 | - json-c-dev 7 | - lcms2-dev 8 | - libdisplay-info-dev 9 | - libevdev-dev 10 | - libinput-dev 11 | - libseat-dev 12 | - libxcb-dev 13 | - libxkbcommon-dev 14 | - mesa-dev 15 | - meson 16 | - pango-dev 17 | - pcre2-dev 18 | - pixman-dev 19 | - scdoc 20 | - wayland-dev 21 | - wayland-protocols 22 | - xcb-util-image-dev 23 | - xcb-util-wm-dev 24 | - xwayland-dev 25 | - hwdata-dev 26 | sources: 27 | - https://github.com/swaywm/sway 28 | - https://gitlab.freedesktop.org/wlroots/wlroots.git 29 | tasks: 30 | - wlroots: | 31 | cd wlroots 32 | meson --prefix=/usr build -Dexamples=false 33 | ninja -C build 34 | sudo ninja -C build install 35 | - setup: | 36 | cd sway 37 | meson build --fatal-meson-warnings -Dauto_features=enabled -Dtray=disabled 38 | - build: | 39 | cd sway 40 | ninja -C build 41 | - build-no-xwayland: | 42 | cd wlroots 43 | meson configure build -Dxwayland=disabled 44 | ninja -C build 45 | sudo ninja -C build install 46 | 47 | cd ../sway 48 | meson configure build --clearcache 49 | ninja -C build 50 | - build-static: | 51 | cd sway 52 | mkdir subprojects 53 | ln -s ../../wlroots subprojects/wlroots 54 | rm -rf build 55 | meson build --fatal-meson-warnings --default-library=static --force-fallback-for=wlroots 56 | ninja -C build 57 | -------------------------------------------------------------------------------- /.builds/archlinux.yml: -------------------------------------------------------------------------------- 1 | image: archlinux 2 | packages: 3 | - cairo 4 | - gdk-pixbuf2 5 | - json-c 6 | - lcms2 7 | - libdisplay-info 8 | - libegl 9 | - libinput 10 | - libxcb 11 | - libxkbcommon 12 | - meson 13 | - pango 14 | - pcre2 15 | - scdoc 16 | - wayland 17 | - wayland-protocols 18 | - xcb-util-image 19 | - xcb-util-wm 20 | - xorg-xwayland 21 | - seatd 22 | - hwdata 23 | sources: 24 | - https://github.com/swaywm/sway 25 | - https://gitlab.freedesktop.org/wlroots/wlroots.git 26 | tasks: 27 | - wlroots: | 28 | cd wlroots 29 | meson --prefix=/usr build -Dexamples=false 30 | ninja -C build 31 | sudo ninja -C build install 32 | - setup: | 33 | cd sway 34 | meson build --fatal-meson-warnings -Dauto_features=enabled -Dsd-bus-provider=libsystemd 35 | - build: | 36 | cd sway 37 | ninja -C build 38 | -------------------------------------------------------------------------------- /.builds/freebsd.yml: -------------------------------------------------------------------------------- 1 | image: freebsd/latest 2 | packages: 3 | - devel/basu 4 | - devel/json-c 5 | - devel/libevdev 6 | - devel/meson 7 | - devel/pcre2 8 | - devel/pkgconf 9 | - graphics/cairo 10 | - graphics/gdk-pixbuf2 11 | - graphics/lcms2 12 | - graphics/wayland 13 | - graphics/wayland-protocols 14 | - textproc/scdoc 15 | - x11-toolkits/pango 16 | - x11/libxcb 17 | - x11/libxkbcommon 18 | # wlroots dependencies 19 | - devel/evdev-proto 20 | - devel/libepoll-shim 21 | - devel/libudev-devd 22 | - graphics/libdrm 23 | - graphics/mesa-libs 24 | - sysutils/libdisplay-info 25 | - sysutils/seatd 26 | - x11/libinput 27 | - x11/libX11 28 | - x11/pixman 29 | - x11/xcb-util-wm 30 | - x11-servers/xwayland 31 | - misc/hwdata 32 | sources: 33 | - https://github.com/swaywm/sway 34 | - https://gitlab.freedesktop.org/wlroots/wlroots.git 35 | tasks: 36 | - setup: | 37 | cd sway 38 | mkdir subprojects 39 | cd subprojects 40 | ln -s ../../wlroots wlroots 41 | cd .. 42 | meson build --fatal-meson-warnings -Dtray=enabled -Dsd-bus-provider=basu 43 | - build: | 44 | cd sway 45 | ninja -C build 46 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # For the full list of code style requirements, see CONTRIBUTING.md 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | 9 | [*.{c,h,cmake,txt}] 10 | indent_style = tab 11 | indent_size = 4 12 | 13 | [*.{xml,yml}] 14 | indent_style = space 15 | indent_size = 2 16 | 17 | [config] 18 | indent_style = space 19 | indent_size = 4 20 | 21 | [*.md] 22 | trim_trailing_whitespace = false 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bugs 3 | about: Crashes and other bugs 4 | labels: 'bug' 5 | 6 | --- 7 | 8 | ### Please read the following before submitting: 9 | - Please do NOT submit bug reports for questions. Ask questions on IRC at #sway on Libera Chat. 10 | - Proprietary graphics drivers, including nvidia, are not supported. Please use the open source equivalents, such as nouveau, if you would like to use Sway. 11 | - Please do NOT submit issues for information from the github wiki. The github wiki is community maintained and therefore may contain outdated information, scripts that don't work or obsolete workarounds. 12 | If you fix a script or find outdated information, don't hesitate to adjust the wiki page. 13 | 14 | ### Please fill out the following: 15 | - **Sway Version:** 16 | - `swaymsg -t get_version` or `sway -v` 17 | 18 | - **Debug Log:** 19 | - Run `sway -d 2> ~/sway.log` from a TTY and upload it to a pastebin, such as gist.github.com. 20 | - This will record information about sway's activity. Please try to keep the reproduction as brief as possible and exit sway. 21 | - Attach the **full** file, do not truncate it. 22 | 23 | - **Configuration File:** 24 | - Please try to produce with the default configuration. 25 | - If you cannot reproduce with the default configuration, please try to find the minimal configuration to reproduce. 26 | - Upload the config to a pastebin such as gist.github.com. 27 | 28 | - **Stack Trace:** 29 | - This is only needed if sway crashes. 30 | - If you use systemd, you should be able to open the coredump of the most recent crash with gdb with 31 | `coredumpctl gdb sway` and then `bt full` to obtain the stack trace. 32 | - If the lines mentioning sway or wlroots have `??` for the location, your binaries were built without debug symbols. Please compile both sway and wlroots from source and try to reproduce. 33 | 34 | - **Description:** 35 | - The steps you took in plain English to reproduce the problem. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Questions 4 | url: "https://libera.chat" 5 | about: "Please ask questions on IRC in #sway on Libera Chat" 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/enhancement.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Enhancements 3 | about: New functionality 4 | labels: 'enhancement' 5 | 6 | --- 7 | 8 | ### Please read the following before submitting: 9 | - We are not accepting any new window management features unless they get implemented by i3. 10 | 11 | ### Please fill out the following: 12 | - **Description:** 13 | Please describe in plain English what the enhancement is and what the use case is. 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/i3_compat.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: i3 Compatibility 3 | about: Sway behaves differently from or lacks i3 functionality 4 | labels: 'i3-compat' 5 | 6 | --- 7 | 8 | ### Please read the following before submitting: 9 | - The following either do not make sense for Wayland or we have decided against supporting: 10 | - `restart` 11 | - `resource` 12 | - saving and loading layouts 13 | - the i3 sync protocol 14 | 15 | ### Please fill out the following: 16 | - **i3 PR:** 17 | - If this is new i3 functionality, please add a link to the i3 pull request. 18 | 19 | - **Description:** 20 | - Please describe in plain English how Sway and i3's behaviors differ or what functionality Sway is lacking. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | install_manifest.txt 2 | *.swp 3 | *.o 4 | *.a 5 | bin/ 6 | test/ 7 | build/ 8 | build-*/ 9 | .cache/ 10 | .lvimrc 11 | config-debug 12 | wayland-*-protocol.* 13 | /subprojects/wlroots 14 | subprojects 15 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Ronan Pigott 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2017 Drew DeVault 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.de.md: -------------------------------------------------------------------------------- 1 | # Sway 2 | Sway ist ein [i3](https://i3wm.org/)-kompatibler [Wayland](http://wayland.freedesktop.org/)-Compositor. Lies die [FAQ](https://github.com/swaywm/sway/wiki). Tritt dem [IRC Channel](https://web.libera.chat/gamja/?channels=#sway) bei (#sway on irc.libera.chat; Englisch). 3 | 4 | ## Signaturen 5 | Jedes Release wird mit dem PGP-Schlüssel [E88F5E48](https://keys.openpgp.org/search?q=34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48) signiert und [auf GitHub](https://github.com/swaywm/sway/releases) veröffentlicht. 6 | 7 | ## Installation 8 | 9 | ### Über die Paketverwaltung 10 | 11 | Sway kann in vielen Distributionen direkt durch die Paketverwaltung installiert werden. Versuche einfach das Packet "sway" zu installieren. 12 | 13 | ### Quellcode selbst kompilieren 14 | 15 | sway benötigt die folgenden Pakete: 16 | 17 | * meson\* 18 | * [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 19 | * wayland 20 | * wayland-protocols\* 21 | * pcre2 22 | * json-c 23 | * pango 24 | * cairo 25 | * gdk-pixbuf2 (Optional, wird für das Benachrichtigungsfeld (System Tray) benötigt) 26 | * [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (Optional, wird für die Dokumentation (Man Pages) benötigt)\* 27 | * git (Optional: Versionsinfo)\* 28 | 29 | _\*Werden nur während des Kompilierens benötigt_ 30 | 31 | Führe die folgenden Befehle aus: 32 | 33 | meson build 34 | ninja -C build 35 | sudo ninja -C build install 36 | 37 | ## Konfiguration 38 | 39 | Falls du von i3 migrierst, kannst du deine Konfigurationsdatei nach `~/.config/sway/config` kopieren und die Einstellungen sollten ohne Weiteres funktionieren. Ansonsten kannst du die Beispielkonfiguration, die normalerweise in `/etc/sway/config` liegt, nach `~/.config/sway/config` kopieren. Die Dokumentation zur Konfigurationsdatei findest du in `man 5 sway`. 40 | 41 | ## Sway starten 42 | Sway kann einfach mit dem Befehl `sway` vom TTY gestartet werden. 43 | Display-Manager werden nicht offiziell unterstützt. Es gibt aber durchaus einige, die mit Sway funktionieren (z.B. gdm). 44 | -------------------------------------------------------------------------------- /README.hi.md: -------------------------------------------------------------------------------- 1 | # sway 2 | 3 | sway एक [i3](https://i3wm.org/)-अनुकूल 4 | [Wayland](https://wayland.freedesktop.org/) Compositor है। 5 | [FAQ](https://github.com/swaywm/sway/wiki) पढिये। [IRC 6 | Channel](https://web.libera.chat/gamja/?channels=#sway) 7 | (irc.libera.chat पर #sway) में भी जुडिये। 8 | 9 | ## रिलीज हस्ताक्षर 10 | 11 | रिलीजें 12 | [E88F5E48](https://keys.openpgp.org/search?q=34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48) 13 | से साइन होतें हैं और [Github पर](https://github.com/swaywm/sway/releases) प्रकाशित होते हैं। 14 | 15 | ## इंस्टौलेशन 16 | 17 | ### पैकेजों के द्वारा 18 | 19 | Sway कई distributions में उप्लब्ध है। आप अपने में "sway" नामक पैकेज इंस्टौल करके देख 20 | सकते हैं। 21 | 22 | ### Source से compile करके 23 | 24 | यदि आप परीक्षण और विकास के लिए sway और wlroots के नवीनतम संस्करण बनाना 25 | चाहते हैं, तो [यह विकी 26 | पृष्ठ](https://github.com/swaywm/sway/wiki/Development-Setup) देखें। 27 | 28 | निर्भरताएं: 29 | 30 | * meson \* 31 | * [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 32 | * wayland 33 | * wayland-protocols \* 34 | * pcre2 35 | * json-c 36 | * pango 37 | * cairo 38 | * gdk-pixbuf (वैकल्पिक: system tray के लिये) 39 | * [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (वैकल्पिक: man पृष्ठों के लिये) 40 | \* 41 | * git (वैकल्पिक: संस्करण जानने के लिये) 42 | 43 | _\* Compilation के समय आवश्यक_ 44 | 45 | ये commands चलाएं: 46 | 47 | meson build/ 48 | ninja -C build/ 49 | sudo ninja -C build/ install 50 | 51 | ## Configuration 52 | 53 | अगर आप पहले से ही i3 का उपयोग करते हैं तो अपने i3 config को 54 | `~/.config/sway/config` में copy कर लीजिये और वह बिना किसी परिवर्तन के काम 55 | करेगा। अन्यथा, नमूने configuration file को `~/.config/sway/config` में copy 56 | कर लीजिये। यह सामान्यतः `/etc/sway/config` में पाया जाता है। `man 5 57 | sway` से आप configuration के बारे में जानकारी प्राप्त कर सकते हैं। 58 | 59 | ## चलाना 60 | 61 | आप एक tty से `sway` को चला सकते हैं। कुछ display managers काम करते हैं परन्तु ये 62 | sway के द्वारा समर्थित नहीं है (gdm के बारे में जाना गया है कि वह सही काम करता 63 | है)। 64 | -------------------------------------------------------------------------------- /README.ja.md: -------------------------------------------------------------------------------- 1 | # sway 2 | 3 | Swayは[i3](https://i3wm.org/)互換な[Wayland](http://wayland.freedesktop.org/)コンポジタです。 4 | [FAQ](https://github.com/swaywm/sway/wiki)も合わせてご覧ください。 5 | [IRC チャンネル](https://web.libera.chat/gamja/?channels=#sway) (irc.libera.chatの#sway)もあります。 6 | 7 | [![](https://sr.ht/ICd5.png)](https://sr.ht/ICd5.png) 8 | 9 | ## 日本語サポート 10 | 11 | SirCmpwnは、日本語でのサポートをIRCとGitHubで行います。タイムゾーンはUTC-4です。 12 | 13 | ## リリースの署名 14 | 15 | Swayのリリースは[E88F5E48](https://keys.openpgp.org/search?q=34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48)で署名され、[GitHub](https://github.com/swaywm/sway/releases)で公開されています。 16 | 17 | ## インストール 18 | 19 | ### パッケージから 20 | 21 | Swayは沢山のディストリビューションで提供されています。"sway"パッケージのインストールを試してください。パッケージが存在しない場合は、[このページ](https://github.com/swaywm/sway/wiki/Unsupported-packages)で、あなたのディストリビューションでのインストールに関する情報を調べてください。 22 | 23 | あなたのディストリビューションにSwayのパッケージを提供したい場合は、SwayのIRCチャンネルを訪れるか、sir@cmpwn.comにメールを送り、相談してください。 24 | 25 | ### ソースコードからコンパイル 26 | 27 | 次の依存パッケージをインストールしてください: 28 | 29 | * meson \* 30 | * [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 31 | * wayland 32 | * wayland-protocols \* 33 | * pcre2 34 | * json-c 35 | * pango 36 | * cairo 37 | * gdk-pixbuf2 (任意: システムイコンで必要です) 38 | * [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (任意: manで必要です) \* 39 | * git (任意: バージョン情報で必要です) \* 40 | 41 | _\*コンパイル時の依存_ 42 | 43 | 次のコマンドを実行してください: 44 | 45 | meson build 46 | ninja -C build 47 | sudo ninja -C build install 48 | 49 | ## 設定 50 | 51 | 既にi3を使用している場合は、i3の設定ファイルを`~/.config/sway/config`にコピーすれば動きます。そうでない場合は、サンプルの設定ファイルを`~/.config/sway/config`にコピーしてください。サンプルの設定ファイルは、通常`/etc/sway/config`にあります。`man 5 sway`を実行することで、設定に関する情報を見ることができます。 52 | 53 | ## 実行 54 | 55 | `sway`をTTYから実行してください。いくつかのディスプレイマネージャは動くかもしれませんが、Swayからサポートされていません(gdmは非常に良く動作することが知られています)。 56 | 57 | -------------------------------------------------------------------------------- /README.ko.md: -------------------------------------------------------------------------------- 1 | # sway 2 | 3 | sway는 [i3](https://i3wm.org/)-호환 [Wayland](http://wayland.freedesktop.org/) 컴포지터입니다. 4 | [FAQ](https://github.com/swaywm/sway/wiki)를 읽어보세요. [IRC 채널](https://web.libera.chat/gamja/?channels=#sway) (#sway on irc.libera.chat)도 있습니다. 5 | 6 | ## 릴리즈 서명 7 | 8 | 릴리즈는 [E88F5E48](https://keys.openpgp.org/search?q=34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48)에서 서명되고, 9 | [GitHub에서](https://github.com/swaywm/sway/releases) 공개되고 있습니다. 10 | 11 | ## 설치 12 | 13 | ### 패키지를 통한 설치 14 | 15 | Sway는 많은 배포판에서 이용할 수 있습니다. "sway" 패키지를 설치해 보세요. 16 | 만약 없다면, [위키 페이지](https://github.com/swaywm/sway/wiki/Unsupported-packages)를 확인하세요. 17 | 해당 배포판에 대한 설치 정보를 확인할 수 있습니다. 18 | 19 | 당신의 배포판에 sway 패키지를 제공하고 싶다면, 20 | IRC 채널을 방문하거나 sir@cmpwn.com으로 이메일을 보내 상담 받으세요. 21 | 22 | ### 소스를 통한 컴파일 23 | 24 | 다음 의존 패키지들을 설치해 주세요: 25 | 26 | * meson \* 27 | * [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 28 | * wayland 29 | * wayland-protocols \* 30 | * pcre2 31 | * json-c 32 | * pango 33 | * cairo 34 | * gdk-pixbuf2 (선택: system tray) 35 | * [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (선택: man pages) \* 36 | * git \* 37 | 38 | _\*컴파일 떄 필요_ 39 | 40 | 다음 명령을 실행하세요: 41 | 42 | meson build 43 | ninja -C build 44 | sudo ninja -C build install 45 | 46 | ## 설정 47 | 48 | i3를 이미 사용 중이라면, i3 config을 `~/.config/sway/config`로 복사하세요. 49 | 아니면, 샘플 구성 파일을 '~/.config/sway/config'에 복사할 수도 있습니다. 50 | 일반적으로 "/etc/sway/config"에 위치해 있습니다. 51 | 설정에 대한 정보를 보려면 "man 5 sway"를 실행하세요. 52 | 53 | ## 실행 54 | 55 | TTY에서 `sway`를 실행하세요. 일부 display manager는 작동하지만, sway로 부터 지원되지 않습니다(gdm은 상당히 잘 작동한다고 알려져 있습니다). 56 | -------------------------------------------------------------------------------- /README.zh-CN.md: -------------------------------------------------------------------------------- 1 | # sway 2 | 3 | sway 是和 [i3](https://i3wm.org/) 兼容的 [Wayland](http://wayland.freedesktop.org/) compositor。 4 | [查看FAQ](https://github.com/swaywm/sway/wiki)/ [加入IRC频道](https://web.libera.chat/gamja/?channels=#sway) (#sway on irc.libera.chat) 5 | 6 | ## 发行签名 7 | 8 | 每个发行版都以 [E88F5E48](https://keys.openpgp.org/search?q=34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48) 的密钥签名并发布在 [GitHub](https://github.com/swaywm/sway/releases)上。 9 | 10 | ## 安装 11 | 12 | ### 从包管理器安装 13 | 14 | Sway 在很多发行版中可用。请尝试在你的发行版中安装 `sway` 。 15 | 16 | ### 从源码编译 17 | 18 | 如果想要构建最新版sway和wlroots用以测试和开发,请查看 [此wiki页面](https://github.com/swaywm/sway/wiki/Development-Setup) 19 | 20 | 安装如下依赖: 21 | 22 | * meson \* 23 | * [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 24 | * wayland 25 | * wayland-protocols \* 26 | * pcre2 27 | * json-c 28 | * pango 29 | * cairo 30 | * gdk-pixbuf2 (可选的: system tray) 31 | * [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (可选: man pages) \* 32 | * git \* 33 | 34 | _\*编译时依赖_ 35 | 36 | 运行如下命令: 37 | 38 | meson build/ 39 | ninja -C build/ 40 | sudo ninja -C build/ install 41 | 42 | ## 配置 43 | 44 | 如果你已经在使用i3,直接复制i3配置文件到 `~/.config/sway/config`,这是开箱即用的。或者,你可以复制配置样例到`~/.config/sway/config`。它通常位于 `/etc/sway/config`。 45 | 运行 `man 5 sway` 获取关于配置的更多信息。 46 | 47 | ## 运行 48 | 49 | 从 TTY 中运行 `sway`。 某些显示管理器(Display Manager)也许可以工作但不被 sway 支持。 50 | (已知 gdm 工作得非常好)。 51 | -------------------------------------------------------------------------------- /README.zh-TW.md: -------------------------------------------------------------------------------- 1 | # sway 2 | 3 | sway 是一個與 [i3](https://i3wm.org/) 相容的 [Wayland](http://wayland.freedesktop.org/) compositor。 4 | 閱讀 [FAQ](https://github.com/swaywm/sway/wiki)。 加入 [IRC 5 | 頻道](https://web.libera.chat/gamja/?channels=#sway) (#sway on 6 | irc.libera.chat) 7 | 8 | ## 發行簽章 9 | 10 | 所有發行的版本都會以 [E88F5E48](https://keys.openpgp.org/search?q=34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48) 簽署 11 | 並發佈於 [GitHub](https://github.com/swaywm/sway/releases) 12 | 13 | ## 安裝 14 | 15 | ### 從套件安裝 16 | 17 | Sway 在許多發行版都有提供。請自己嘗試於你的發行版安裝 「sway」這個套件。 18 | 如果無法取得,請查看 [這個 wiki 頁面](https://github.com/swaywm/sway/wiki/Unsupported-packages) 19 | 以取得更多關於如何於你使用的發行版上安裝的資訊。 20 | 21 | 如果你想要為你使用的發行版包裝 sway,請到 IRC 頻道或是直接寄封信到 sir@cmpwn.com 來取得一些建議。 22 | 23 | ### 從原始碼編譯 24 | 25 | 相依套件: 26 | 27 | * meson \* 28 | * [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 29 | * wayland 30 | * wayland-protocols \* 31 | * pcre2 32 | * json-c 33 | * pango 34 | * cairo 35 | * gdk-pixbuf2 (選擇性: system tray) 36 | * [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (選擇性: man pages) \* 37 | * git \* 38 | 39 | _\*編譯時相依_ 40 | 41 | 執行這些指令: 42 | 43 | meson build 44 | ninja -C build 45 | sudo ninja -C build install 46 | 47 | ## 設定檔 48 | 49 | 如果你已經在使用 i3,你可以直接將你的 i3 設定檔複製到 `~/.config/sway/config` 然後就能直接使用。 50 | 或者你也可以把範例設定檔複製到 `~/.config/sway/config`。 它通常會在 `/etc/sway/config`。 51 | 執行 `man 5 sway` 來取得更多關於設定檔的資訊。 52 | 53 | ## 執行 54 | 55 | 在 TTY 執行 `sway`。有些 display manager 可能可以運作但 sway 不提供支援 (已知 gdm 運作的很好) 56 | -------------------------------------------------------------------------------- /assets/Sway_Logo+Text_Ver1_1500x716.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Logo+Text_Ver1_1500x716.png -------------------------------------------------------------------------------- /assets/Sway_Logo+Text_Ver2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Logo+Text_Ver2.png -------------------------------------------------------------------------------- /assets/Sway_Logo+Text_Ver3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Logo+Text_Ver3.png -------------------------------------------------------------------------------- /assets/Sway_Logo+Text_Ver4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Logo+Text_Ver4.png -------------------------------------------------------------------------------- /assets/Sway_Tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Tree.png -------------------------------------------------------------------------------- /assets/Sway_Tree_1000x934.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Tree_1000x934.png -------------------------------------------------------------------------------- /assets/Sway_Wallpaper_Blue_1136x640.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Wallpaper_Blue_1136x640.png -------------------------------------------------------------------------------- /assets/Sway_Wallpaper_Blue_1136x640_Portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Wallpaper_Blue_1136x640_Portrait.png -------------------------------------------------------------------------------- /assets/Sway_Wallpaper_Blue_1366x768.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Wallpaper_Blue_1366x768.png -------------------------------------------------------------------------------- /assets/Sway_Wallpaper_Blue_1920x1080.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Wallpaper_Blue_1920x1080.png -------------------------------------------------------------------------------- /assets/Sway_Wallpaper_Blue_2048x1536.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Wallpaper_Blue_2048x1536.png -------------------------------------------------------------------------------- /assets/Sway_Wallpaper_Blue_2048x1536_Portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Wallpaper_Blue_2048x1536_Portrait.png -------------------------------------------------------------------------------- /assets/Sway_Wallpaper_Blue_768x1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Wallpaper_Blue_768x1024.png -------------------------------------------------------------------------------- /assets/Sway_Wallpaper_Blue_768x1024_Portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaywm/sway/6816b51c86846afc5eaa1dea2541410058347a6e/assets/Sway_Wallpaper_Blue_768x1024_Portrait.png -------------------------------------------------------------------------------- /client/meson.build: -------------------------------------------------------------------------------- 1 | lib_sway_client = static_library( 2 | 'sway-client', 3 | files( 4 | 'pool-buffer.c', 5 | ), 6 | dependencies: [ 7 | cairo, 8 | pango, 9 | pangocairo, 10 | wayland_client 11 | ], 12 | link_with: [lib_sway_common], 13 | include_directories: sway_inc 14 | ) 15 | -------------------------------------------------------------------------------- /common/cairo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "cairo_util.h" 4 | 5 | void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { 6 | cairo_set_source_rgba(cairo, 7 | (color >> (3*8) & 0xFF) / 255.0, 8 | (color >> (2*8) & 0xFF) / 255.0, 9 | (color >> (1*8) & 0xFF) / 255.0, 10 | (color >> (0*8) & 0xFF) / 255.0); 11 | } 12 | 13 | cairo_subpixel_order_t to_cairo_subpixel_order(enum wl_output_subpixel subpixel) { 14 | switch (subpixel) { 15 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: 16 | return CAIRO_SUBPIXEL_ORDER_RGB; 17 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: 18 | return CAIRO_SUBPIXEL_ORDER_BGR; 19 | case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: 20 | return CAIRO_SUBPIXEL_ORDER_VRGB; 21 | case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: 22 | return CAIRO_SUBPIXEL_ORDER_VBGR; 23 | default: 24 | return CAIRO_SUBPIXEL_ORDER_DEFAULT; 25 | } 26 | return CAIRO_SUBPIXEL_ORDER_DEFAULT; 27 | } 28 | 29 | cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, 30 | int width, int height) { 31 | int image_width = cairo_image_surface_get_width(image); 32 | int image_height = cairo_image_surface_get_height(image); 33 | 34 | cairo_surface_t *new = 35 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); 36 | cairo_t *cairo = cairo_create(new); 37 | cairo_scale(cairo, (double)width / image_width, 38 | (double)height / image_height); 39 | cairo_set_source_surface(cairo, image, 0, 0); 40 | 41 | cairo_paint(cairo); 42 | cairo_destroy(cairo); 43 | return new; 44 | } 45 | -------------------------------------------------------------------------------- /common/meson.build: -------------------------------------------------------------------------------- 1 | lib_sway_common = static_library( 2 | 'sway-common', 3 | files( 4 | 'cairo.c', 5 | 'gesture.c', 6 | 'ipc-client.c', 7 | 'log.c', 8 | 'loop.c', 9 | 'list.c', 10 | 'pango.c', 11 | 'stringop.c', 12 | 'util.c' 13 | ), 14 | dependencies: [ 15 | cairo, 16 | pango, 17 | pangocairo, 18 | wayland_client.partial_dependency(compile_args: true) 19 | ], 20 | include_directories: sway_inc 21 | ) 22 | -------------------------------------------------------------------------------- /completions/bash/sway: -------------------------------------------------------------------------------- 1 | # sway(1) completion 2 | 3 | _sway() 4 | { 5 | local cur prev short long 6 | _get_comp_words_by_ref cur prev 7 | 8 | short=( 9 | -h 10 | -c 11 | -C 12 | -d 13 | -v 14 | -V 15 | ) 16 | 17 | long=( 18 | --help 19 | --config 20 | --validate 21 | --debug 22 | --version 23 | --verbose 24 | --get-socketpath 25 | ) 26 | 27 | case $prev in 28 | -c|--config) 29 | _filedir 30 | return 31 | ;; 32 | esac 33 | 34 | if [[ $cur == --* ]]; then 35 | COMPREPLY=($(compgen -W "${long[*]}" -- "$cur")) 36 | elif [[ $cur == -* ]]; then 37 | COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) 38 | COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) 39 | else 40 | COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) 41 | COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) 42 | COMPREPLY+=($(compgen -c -- "$cur")) 43 | fi 44 | 45 | } && 46 | complete -F _sway sway 47 | -------------------------------------------------------------------------------- /completions/bash/swaybar: -------------------------------------------------------------------------------- 1 | # swaybar(1) completion 2 | 3 | _swaybar() 4 | { 5 | local cur prev short long 6 | _get_comp_words_by_ref cur prev 7 | 8 | short=( 9 | -h 10 | -v 11 | -s 12 | -b 13 | -d 14 | ) 15 | 16 | long=( 17 | --help 18 | --version 19 | --socket 20 | --bar_id 21 | --debug 22 | ) 23 | 24 | case $prev in 25 | -s|--socket) 26 | _filedir 27 | return 28 | ;; 29 | -b|--bar_id) 30 | bars=($(swaymsg -t get_bar_config | jq -r '.[]')) 31 | COMPREPLY=($(compgen -W "${bars[*]}" -- "$cur")) 32 | return 33 | ;; 34 | esac 35 | 36 | if [[ $cur == --* ]]; then 37 | COMPREPLY=($(compgen -W "${long[*]}" -- "$cur")) 38 | else 39 | COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) 40 | COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) 41 | fi 42 | 43 | } && 44 | complete -F _swaybar swaybar 45 | -------------------------------------------------------------------------------- /completions/bash/swaymsg: -------------------------------------------------------------------------------- 1 | # swaymsg(1) completion 2 | 3 | _swaymsg() 4 | { 5 | local cur prev types short long 6 | _get_comp_words_by_ref cur prev 7 | 8 | types=( 9 | 'get_workspaces' 10 | 'get_seats' 11 | 'get_inputs' 12 | 'get_outputs' 13 | 'get_tree' 14 | 'get_marks' 15 | 'get_bar_config' 16 | 'get_version' 17 | 'get_binding_modes' 18 | 'get_binding_state' 19 | 'get_config' 20 | 'send_tick' 21 | 'subscribe' 22 | ) 23 | 24 | short=( 25 | -h 26 | -m 27 | -p 28 | -q 29 | -r 30 | -s 31 | -t 32 | -v 33 | ) 34 | 35 | long=( 36 | --help 37 | --monitor 38 | --pretty 39 | --quiet 40 | --raw 41 | --socket 42 | --type 43 | --version 44 | ) 45 | 46 | case $prev in 47 | -s|--socket) 48 | _filedir 49 | return 50 | ;; 51 | -t|--type) 52 | COMPREPLY=($(compgen -W "${types[*]}" -- "$cur")) 53 | return 54 | ;; 55 | esac 56 | 57 | if [[ $cur == --* ]]; then 58 | COMPREPLY=($(compgen -W "${long[*]}" -- "$cur")) 59 | else 60 | COMPREPLY=($(compgen -W "${short[*]}" -- "$cur")) 61 | COMPREPLY+=($(compgen -W "${long[*]}" -- "$cur")) 62 | fi 63 | 64 | } && 65 | complete -F _swaymsg swaymsg 66 | -------------------------------------------------------------------------------- /completions/fish/sway.fish: -------------------------------------------------------------------------------- 1 | # sway(1) completion 2 | 3 | complete -f -c sway 4 | complete -c sway -s h -l help --description "Show help message and quit." 5 | complete -c sway -s c -l config --description "Specifies a config file." -r 6 | complete -c sway -s C -l validate --description "Check the validity of the config file, then exit." 7 | complete -c sway -s d -l debug --description "Enables full logging, including debug information." 8 | complete -c sway -s v -l version --description "Show the version number and quit." 9 | complete -c sway -s V -l verbose --description "Enables more verbose logging." 10 | complete -c sway -l get-socketpath --description "Gets the IPC socket path and prints it, then exits." 11 | 12 | -------------------------------------------------------------------------------- /completions/meson.build: -------------------------------------------------------------------------------- 1 | if get_option('zsh-completions') 2 | zsh_files = files( 3 | 'zsh/_sway', 4 | 'zsh/_swaymsg', 5 | ) 6 | zsh_install_dir = join_paths(datadir, 'zsh', 'site-functions') 7 | 8 | install_data(zsh_files, install_dir: zsh_install_dir) 9 | endif 10 | 11 | if get_option('bash-completions') 12 | bash_comp = dependency('bash-completion', required: false) 13 | 14 | bash_files = files( 15 | 'bash/sway', 16 | 'bash/swaymsg', 17 | ) 18 | 19 | if get_option('swaybar') 20 | bash_files += files('bash/swaybar') 21 | endif 22 | 23 | if bash_comp.found() 24 | bash_install_dir = bash_comp.get_variable( 25 | pkgconfig: 'completionsdir', 26 | pkgconfig_define: ['datadir', datadir] 27 | ) 28 | else 29 | bash_install_dir = join_paths(datadir, 'bash-completion', 'completions') 30 | endif 31 | 32 | install_data(bash_files, install_dir: bash_install_dir) 33 | endif 34 | 35 | if get_option('fish-completions') 36 | fish_comp = dependency('fish', required: false) 37 | 38 | fish_files = files( 39 | 'fish/sway.fish', 40 | 'fish/swaymsg.fish', 41 | ) 42 | 43 | if get_option('swaynag') 44 | fish_files += files('fish/swaynag.fish') 45 | endif 46 | 47 | if fish_comp.found() 48 | fish_install_dir = fish_comp.get_variable( 49 | pkgconfig: 'completionsdir', 50 | pkgconfig_define: ['datadir', datadir] 51 | ) 52 | else 53 | fish_install_dir = join_paths(datadir, 'fish', 'vendor_completions.d') 54 | endif 55 | 56 | install_data(fish_files, install_dir: fish_install_dir) 57 | endif 58 | -------------------------------------------------------------------------------- /completions/zsh/_sway: -------------------------------------------------------------------------------- 1 | #compdef sway 2 | #------------ 3 | # Description 4 | # ----------- 5 | # 6 | # Completion script for the sway window manager (http://swaywm.org) 7 | # 8 | # --------------------------------------------- 9 | # Author 10 | # ------- 11 | # 12 | # * Seth Barberee 13 | # 14 | # ------------------------------- 15 | _arguments -s \ 16 | '(-v --version)'{-v,--version}'[Show the version number and quit]' \ 17 | '(-h --help)'{-h,--help}'[Show help message and quit]' \ 18 | '(-c --config)'{-c,--config}'[Specify a config file]:files:_files' \ 19 | '(-C --validate)'{-C,--validate}'[Check validity of the config file, then exit]' \ 20 | '(-d --debug)'{-d,--debug}'[Enables full logging, including debug information]' \ 21 | '(-V --verbose)'{-V,--verbose}'[Enables more verbose logging]' \ 22 | '(--get-socketpath)'--get-socketpath'[Gets the IPC socket path and prints it, then exits]' 23 | -------------------------------------------------------------------------------- /completions/zsh/_swaybar: -------------------------------------------------------------------------------- 1 | #compdef swaybar 2 | # 3 | # Completion script for swaybar 4 | # 5 | 6 | local bars=($(swaymsg -t get_bar_config | jq -r '.[]')) 7 | 8 | _arguments -s \ 9 | '(-h --help)'{-h,--help}'[Show help message and quit]' \ 10 | '(-v --version)'{-v,--version}'[Show version and quit]' \ 11 | '(-s --socket)'{-s,--socket}'[Connect to sway via socket]:filename:_files' \ 12 | '(-b --bar_id)'{-b,--bar-id}'[Bar ID for which to get the configuration]:filename:($bars)'\ 13 | '(-d --debug)'{-d,--debug}'[Enable debugging]' 14 | -------------------------------------------------------------------------------- /completions/zsh/_swaymsg: -------------------------------------------------------------------------------- 1 | #compdef swaymsg 2 | #----------------- 3 | # Description 4 | # ----------- 5 | # 6 | # Completion script for swaymsg in sway wm (http://swaywm.org) 7 | # 8 | # ------------------------------------------------------ 9 | # Author 10 | # -------- 11 | # 12 | # * Seth Barberee 13 | # 14 | # ------------------------------------------- 15 | 16 | types=( 17 | 'get_workspaces' 18 | 'get_seats' 19 | 'get_inputs' 20 | 'get_outputs' 21 | 'get_tree' 22 | 'get_marks' 23 | 'get_bar_config' 24 | 'get_version' 25 | 'get_binding_modes' 26 | 'get_binding_state' 27 | 'get_config' 28 | 'send_tick' 29 | 'subscribe' 30 | ) 31 | 32 | _arguments -s \ 33 | '(-h --help)'{-h,--help}'[Show help message and quit]' \ 34 | '(-m --monitor)'{-m,--monitor}'[Monitor until killed (-t SUBSCRIBE only)]' \ 35 | '(-p --pretty)'{-p,--pretty}'[Use pretty output even when not using a tty]' \ 36 | '(-q --quiet)'{-q,--quiet}'[Be quiet]' \ 37 | '(-r --raw)'{-r,--raw}'[Use raw output even if using a tty]' \ 38 | '(-s --socket)'{-s,--socket}'[Use the specified socket path]:files:_files' \ 39 | '(-t --type)'{-t,--type}'[Specify the message type]:type:{_describe "type" types}' \ 40 | '(-v --version)'{-v,--version}'[Show the version number and quit]' 41 | -------------------------------------------------------------------------------- /include/cairo_util.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_CAIRO_UTIL_H 2 | #define _SWAY_CAIRO_UTIL_H 3 | #include "config.h" 4 | #include 5 | #include 6 | #include 7 | 8 | void cairo_set_source_u32(cairo_t *cairo, uint32_t color); 9 | cairo_subpixel_order_t to_cairo_subpixel_order(enum wl_output_subpixel subpixel); 10 | 11 | cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, 12 | int width, int height); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /include/ipc-client.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_IPC_CLIENT_H 2 | #define _SWAY_IPC_CLIENT_H 3 | 4 | // arbitrary number, it's probably sufficient, higher number = more memory usage 5 | #define JSON_MAX_DEPTH 512 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "ipc.h" 12 | 13 | /** 14 | * IPC response including type of IPC response, size of payload and the json 15 | * encoded payload string. 16 | */ 17 | struct ipc_response { 18 | uint32_t size; 19 | uint32_t type; 20 | char *payload; 21 | }; 22 | 23 | /** 24 | * Gets the path to the IPC socket from sway. 25 | */ 26 | char *get_socketpath(void); 27 | /** 28 | * Opens the sway socket. 29 | */ 30 | int ipc_open_socket(const char *socket_path); 31 | /** 32 | * Issues a single IPC command and returns the buffer. len will be updated with 33 | * the length of the buffer returned from sway. 34 | */ 35 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len); 36 | /** 37 | * Receives a single IPC response and returns an ipc_response. 38 | */ 39 | struct ipc_response *ipc_recv_response(int socketfd); 40 | /** 41 | * Free ipc_response struct 42 | */ 43 | void free_ipc_response(struct ipc_response *response); 44 | /** 45 | * Sets the receive timeout for the IPC socket 46 | */ 47 | bool ipc_set_recv_timeout(int socketfd, struct timeval tv); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/ipc.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_IPC_H 2 | #define _SWAY_IPC_H 3 | 4 | #define event_mask(ev) (1 << (ev & 0x7F)) 5 | 6 | enum ipc_command_type { 7 | // i3 command types - see i3's I3_REPLY_TYPE constants 8 | IPC_COMMAND = 0, 9 | IPC_GET_WORKSPACES = 1, 10 | IPC_SUBSCRIBE = 2, 11 | IPC_GET_OUTPUTS = 3, 12 | IPC_GET_TREE = 4, 13 | IPC_GET_MARKS = 5, 14 | IPC_GET_BAR_CONFIG = 6, 15 | IPC_GET_VERSION = 7, 16 | IPC_GET_BINDING_MODES = 8, 17 | IPC_GET_CONFIG = 9, 18 | IPC_SEND_TICK = 10, 19 | IPC_SYNC = 11, 20 | IPC_GET_BINDING_STATE = 12, 21 | 22 | // sway-specific command types 23 | IPC_GET_INPUTS = 100, 24 | IPC_GET_SEATS = 101, 25 | 26 | // Events sent from sway to clients. Events have the highest bits set. 27 | IPC_EVENT_WORKSPACE = ((1<<31) | 0), 28 | IPC_EVENT_OUTPUT = ((1<<31) | 1), 29 | IPC_EVENT_MODE = ((1<<31) | 2), 30 | IPC_EVENT_WINDOW = ((1<<31) | 3), 31 | IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4), 32 | IPC_EVENT_BINDING = ((1<<31) | 5), 33 | IPC_EVENT_SHUTDOWN = ((1<<31) | 6), 34 | IPC_EVENT_TICK = ((1<<31) | 7), 35 | 36 | // sway-specific event types 37 | IPC_EVENT_BAR_STATE_UPDATE = ((1<<31) | 20), 38 | IPC_EVENT_INPUT = ((1<<31) | 21), 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/list.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_LIST_H 2 | #define _SWAY_LIST_H 3 | 4 | typedef struct { 5 | int capacity; 6 | int length; 7 | void **items; 8 | } list_t; 9 | 10 | list_t *create_list(void); 11 | void list_free(list_t *list); 12 | void list_add(list_t *list, void *item); 13 | void list_insert(list_t *list, int index, void *item); 14 | void list_del(list_t *list, int index); 15 | void list_cat(list_t *list, list_t *source); 16 | // See qsort. Remember to use *_qsort functions as compare functions, 17 | // because they dereference the left and right arguments first! 18 | void list_qsort(list_t *list, int compare(const void *left, const void *right)); 19 | // Return index for first item in list that returns 0 for given compare 20 | // function or -1 if none matches. 21 | int list_seq_find(list_t *list, int compare(const void *item, const void *cmp_to), const void *cmp_to); 22 | int list_find(list_t *list, const void *item); 23 | // stable sort since qsort is not guaranteed to be stable 24 | void list_stable_sort(list_t *list, int compare(const void *a, const void *b)); 25 | // swap two elements in a list 26 | void list_swap(list_t *list, int src, int dest); 27 | // move item to end of list 28 | void list_move_to_end(list_t *list, void *item); 29 | 30 | /* Calls `free` for each item in the list, then frees the list. 31 | * Do not use this to free lists of primitives or items that require more 32 | * complicated deallocation code. 33 | */ 34 | void list_free_items_and_destroy(list_t *list); 35 | #endif 36 | -------------------------------------------------------------------------------- /include/log.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_LOG_H 2 | #define _SWAY_LOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | typedef enum { 10 | SWAY_SILENT = 0, 11 | SWAY_ERROR = 1, 12 | SWAY_INFO = 2, 13 | SWAY_DEBUG = 3, 14 | SWAY_LOG_IMPORTANCE_LAST, 15 | } sway_log_importance_t; 16 | 17 | #ifdef __GNUC__ 18 | #define ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end))) 19 | #else 20 | #define ATTRIB_PRINTF(start, end) 21 | #endif 22 | 23 | void error_handler(int sig); 24 | 25 | typedef void (*terminate_callback_t)(int exit_code); 26 | 27 | // Will log all messages less than or equal to `verbosity` 28 | // The `terminate` callback is called by `sway_abort` 29 | void sway_log_init(sway_log_importance_t verbosity, terminate_callback_t terminate); 30 | 31 | void _sway_log(sway_log_importance_t verbosity, const char *format, ...) ATTRIB_PRINTF(2, 3); 32 | void _sway_vlog(sway_log_importance_t verbosity, const char *format, va_list args) ATTRIB_PRINTF(2, 0); 33 | void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2); 34 | bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3); 35 | 36 | #ifdef SWAY_REL_SRC_DIR 37 | // strip prefix from __FILE__, leaving the path relative to the project root 38 | #define _SWAY_FILENAME ((const char *)__FILE__ + sizeof(SWAY_REL_SRC_DIR) - 1) 39 | #else 40 | #define _SWAY_FILENAME __FILE__ 41 | #endif 42 | 43 | #define sway_log(verb, fmt, ...) \ 44 | _sway_log(verb, "[%s:%d] " fmt, _SWAY_FILENAME, __LINE__, ##__VA_ARGS__) 45 | 46 | #define sway_vlog(verb, fmt, args) \ 47 | _sway_vlog(verb, "[%s:%d] " fmt, _SWAY_FILENAME, __LINE__, args) 48 | 49 | #define sway_log_errno(verb, fmt, ...) \ 50 | sway_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno)) 51 | 52 | #define sway_abort(FMT, ...) \ 53 | _sway_abort("[%s:%d] " FMT, _SWAY_FILENAME, __LINE__, ##__VA_ARGS__) 54 | 55 | #define sway_assert(COND, FMT, ...) \ 56 | _sway_assert(COND, "[%s:%d] %s:" FMT, _SWAY_FILENAME, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__) 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/loop.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_LOOP_H 2 | #define _SWAY_LOOP_H 3 | #include 4 | 5 | /** 6 | * This is an event loop system designed for sway clients, not sway itself. 7 | * 8 | * The loop consists of file descriptors and timers. Typically the Wayland 9 | * display's file descriptor will be one of the fds in the loop. 10 | */ 11 | 12 | struct loop; 13 | struct loop_timer; 14 | 15 | /** 16 | * Create an event loop. 17 | */ 18 | struct loop *loop_create(void); 19 | 20 | /** 21 | * Destroy the event loop (eg. on program termination). 22 | */ 23 | void loop_destroy(struct loop *loop); 24 | 25 | /** 26 | * Poll the event loop. This will block until one of the fds has data. 27 | */ 28 | void loop_poll(struct loop *loop); 29 | 30 | /** 31 | * Add a file descriptor to the loop. 32 | */ 33 | void loop_add_fd(struct loop *loop, int fd, short mask, 34 | void (*func)(int fd, short mask, void *data), void *data); 35 | 36 | /** 37 | * Add a timer to the loop. 38 | * 39 | * When the timer expires, the timer will be removed from the loop and freed. 40 | */ 41 | struct loop_timer *loop_add_timer(struct loop *loop, int ms, 42 | void (*callback)(void *data), void *data); 43 | 44 | /** 45 | * Remove a file descriptor from the loop. 46 | */ 47 | bool loop_remove_fd(struct loop *loop, int fd); 48 | 49 | /** 50 | * Remove a timer from the loop. 51 | */ 52 | bool loop_remove_timer(struct loop *loop, struct loop_timer *timer); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/meson.build: -------------------------------------------------------------------------------- 1 | configure_file(output: 'config.h', configuration: conf_data) 2 | -------------------------------------------------------------------------------- /include/pango.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_PANGO_H 2 | #define _SWAY_PANGO_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "stringop.h" 9 | 10 | /** 11 | * Utility function which escape characters a & < > ' ". 12 | * 13 | * The function returns the length of the escaped string, optionally writing the 14 | * escaped string to dest if provided. 15 | */ 16 | size_t escape_markup_text(const char *src, char *dest); 17 | PangoLayout *get_pango_layout(cairo_t *cairo, const PangoFontDescription *desc, 18 | const char *text, double scale, bool markup); 19 | void get_text_size(cairo_t *cairo, const PangoFontDescription *desc, int *width, int *height, 20 | int *baseline, double scale, bool markup, const char *fmt, ...) _SWAY_ATTRIB_PRINTF(8, 9); 21 | void get_text_metrics(const PangoFontDescription *desc, int *height, int *baseline); 22 | void render_text(cairo_t *cairo, PangoFontDescription *desc, 23 | double scale, bool markup, const char *fmt, ...) _SWAY_ATTRIB_PRINTF(5, 6); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/pool-buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_BUFFERS_H 2 | #define _SWAY_BUFFERS_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | struct pool_buffer { 10 | struct wl_buffer *buffer; 11 | cairo_surface_t *surface; 12 | cairo_t *cairo; 13 | PangoContext *pango; 14 | uint32_t width, height; 15 | void *data; 16 | size_t size; 17 | bool busy; 18 | }; 19 | 20 | struct pool_buffer *get_next_buffer(struct wl_shm *shm, 21 | struct pool_buffer pool[static 2], uint32_t width, uint32_t height); 22 | void destroy_buffer(struct pool_buffer *buffer); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/stringop.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_STRINGOP_H 2 | #define _SWAY_STRINGOP_H 3 | 4 | #include 5 | #include 6 | #include "list.h" 7 | 8 | #ifdef __GNUC__ 9 | #define _SWAY_ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end))) 10 | #else 11 | #define _SWAY_ATTRIB_PRINTF(start, end) 12 | #endif 13 | 14 | void strip_whitespace(char *str); 15 | void strip_quotes(char *str); 16 | 17 | // strcat that does nothing if dest or src is NULL 18 | char *lenient_strcat(char *dest, const char *src); 19 | char *lenient_strncat(char *dest, const char *src, size_t len); 20 | 21 | // strcmp that also handles null pointers. 22 | int lenient_strcmp(const char *a, const char *b); 23 | 24 | // Simply split a string with delims, free with `list_free_items_and_destroy` 25 | list_t *split_string(const char *str, const char *delims); 26 | 27 | // Splits an argument string, keeping quotes intact 28 | char **split_args(const char *str, int *argc); 29 | void free_argv(int argc, char **argv); 30 | 31 | int unescape_string(char *string); 32 | char *join_args(char **argv, int argc); 33 | 34 | // Split string into 2 by delim, handle quotes 35 | char *argsep(char **stringp, const char *delim, char *matched_delim); 36 | 37 | // Expand a path using shell replacements such as $HOME and ~ 38 | bool expand_path(char **path); 39 | 40 | char *vformat_str(const char *fmt, va_list args) _SWAY_ATTRIB_PRINTF(1, 0); 41 | char *format_str(const char *fmt, ...) _SWAY_ATTRIB_PRINTF(1, 2); 42 | 43 | bool has_prefix(const char *str, const char *prefix); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/sway/decoration.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_DECORATION_H 2 | #define _SWAY_DECORATION_H 3 | 4 | #include 5 | 6 | struct sway_server_decoration { 7 | struct wlr_server_decoration *wlr_server_decoration; 8 | struct wl_list link; 9 | 10 | struct wl_listener destroy; 11 | struct wl_listener mode; 12 | }; 13 | 14 | struct sway_server_decoration *decoration_from_surface( 15 | struct wlr_surface *surface); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/sway/desktop/idle_inhibit_v1.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_DESKTOP_IDLE_INHIBIT_V1_H 2 | #define _SWAY_DESKTOP_IDLE_INHIBIT_V1_H 3 | #include 4 | 5 | enum sway_idle_inhibit_mode { 6 | INHIBIT_IDLE_APPLICATION, // Application set inhibitor (when visible) 7 | INHIBIT_IDLE_FOCUS, // User set inhibitor when focused 8 | INHIBIT_IDLE_FULLSCREEN, // User set inhibitor when fullscreen + visible 9 | INHIBIT_IDLE_OPEN, // User set inhibitor while open 10 | INHIBIT_IDLE_VISIBLE // User set inhibitor when visible 11 | }; 12 | 13 | struct sway_idle_inhibit_manager_v1 { 14 | struct wlr_idle_inhibit_manager_v1 *wlr_manager; 15 | struct wl_listener new_idle_inhibitor_v1; 16 | struct wl_listener manager_destroy; 17 | struct wl_list inhibitors; 18 | }; 19 | 20 | struct sway_idle_inhibitor_v1 { 21 | struct wlr_idle_inhibitor_v1 *wlr_inhibitor; 22 | struct sway_view *view; 23 | enum sway_idle_inhibit_mode mode; 24 | 25 | struct wl_list link; 26 | struct wl_listener destroy; 27 | }; 28 | 29 | bool sway_idle_inhibit_v1_is_active( 30 | struct sway_idle_inhibitor_v1 *inhibitor); 31 | 32 | void sway_idle_inhibit_v1_check_active(void); 33 | 34 | void sway_idle_inhibit_v1_user_inhibitor_register(struct sway_view *view, 35 | enum sway_idle_inhibit_mode mode); 36 | 37 | struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_user_inhibitor_for_view( 38 | struct sway_view *view); 39 | 40 | struct sway_idle_inhibitor_v1 *sway_idle_inhibit_v1_application_inhibitor_for_view( 41 | struct sway_view *view); 42 | 43 | void sway_idle_inhibit_v1_user_inhibitor_destroy( 44 | struct sway_idle_inhibitor_v1 *inhibitor); 45 | 46 | bool sway_idle_inhibit_manager_v1_init(void); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/sway/desktop/launcher.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_LAUNCHER_H 2 | #define _SWAY_LAUNCHER_H 3 | 4 | #include 5 | #include 6 | #include "sway/input/seat.h" 7 | 8 | struct launcher_ctx { 9 | pid_t pid; 10 | char *fallback_name; 11 | struct wlr_xdg_activation_token_v1 *token; 12 | struct wl_listener token_destroy; 13 | struct sway_seat *seat; 14 | struct wl_listener seat_destroy; 15 | 16 | bool activated; 17 | bool had_focused_surface; 18 | 19 | struct sway_node *node; 20 | struct wl_listener node_destroy; 21 | 22 | struct wl_list link; // sway_server::pending_launcher_ctxs 23 | }; 24 | 25 | struct launcher_ctx *launcher_ctx_find_pid(pid_t pid); 26 | 27 | struct sway_workspace *launcher_ctx_get_workspace(struct launcher_ctx *ctx); 28 | 29 | void launcher_ctx_consume(struct launcher_ctx *ctx); 30 | 31 | void launcher_ctx_destroy(struct launcher_ctx *ctx); 32 | 33 | struct launcher_ctx *launcher_ctx_create_internal(void); 34 | 35 | struct launcher_ctx *launcher_ctx_create( 36 | struct wlr_xdg_activation_token_v1 *token, struct sway_node *node); 37 | 38 | const char *launcher_ctx_get_token_name(struct launcher_ctx *ctx); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/sway/input/libinput.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_INPUT_LIBINPUT_H 2 | #define _SWAY_INPUT_LIBINPUT_H 3 | #include "sway/input/input-manager.h" 4 | 5 | bool sway_input_configure_libinput_device(struct sway_input_device *device); 6 | 7 | void sway_input_configure_libinput_device_send_events( 8 | struct sway_input_device *device); 9 | 10 | void sway_input_reset_libinput_device(struct sway_input_device *device); 11 | 12 | bool sway_libinput_device_is_builtin(struct sway_input_device *device); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /include/sway/input/switch.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_INPUT_SWITCH_H 2 | #define _SWAY_INPUT_SWITCH_H 3 | 4 | #include "sway/input/seat.h" 5 | 6 | struct sway_switch { 7 | struct sway_seat_device *seat_device; 8 | struct wlr_switch *wlr; 9 | enum wlr_switch_state state; 10 | enum wlr_switch_type type; 11 | 12 | struct wl_listener switch_toggle; 13 | }; 14 | 15 | struct sway_switch *sway_switch_create(struct sway_seat *seat, 16 | struct sway_seat_device *device); 17 | 18 | void sway_switch_configure(struct sway_switch *sway_switch); 19 | 20 | void sway_switch_destroy(struct sway_switch *sway_switch); 21 | 22 | void sway_switch_retrigger_bindings_for_all(void); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/sway/input/tablet.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_INPUT_TABLET_H 2 | #define _SWAY_INPUT_TABLET_H 3 | #include 4 | 5 | struct sway_seat; 6 | struct wlr_tablet_tool; 7 | 8 | struct sway_tablet { 9 | struct wl_list link; 10 | struct sway_seat_device *seat_device; 11 | struct wlr_tablet_v2_tablet *tablet_v2; 12 | }; 13 | 14 | enum sway_tablet_tool_mode { 15 | SWAY_TABLET_TOOL_MODE_ABSOLUTE, 16 | SWAY_TABLET_TOOL_MODE_RELATIVE, 17 | }; 18 | 19 | struct sway_tablet_tool { 20 | struct sway_seat *seat; 21 | struct sway_tablet *tablet; 22 | struct wlr_tablet_v2_tablet_tool *tablet_v2_tool; 23 | 24 | enum sway_tablet_tool_mode mode; 25 | double tilt_x, tilt_y; 26 | 27 | struct wl_listener set_cursor; 28 | struct wl_listener tool_destroy; 29 | }; 30 | 31 | struct sway_tablet_pad { 32 | struct wl_list link; 33 | struct sway_seat_device *seat_device; 34 | struct sway_tablet *tablet; 35 | struct wlr_tablet_pad *wlr; 36 | struct wlr_tablet_v2_tablet_pad *tablet_v2_pad; 37 | 38 | struct wl_listener attach; 39 | struct wl_listener button; 40 | struct wl_listener ring; 41 | struct wl_listener strip; 42 | 43 | struct wlr_surface *current_surface; 44 | struct wl_listener surface_destroy; 45 | 46 | struct wl_listener tablet_destroy; 47 | }; 48 | 49 | struct sway_tablet *sway_tablet_create(struct sway_seat *seat, 50 | struct sway_seat_device *device); 51 | 52 | void sway_configure_tablet(struct sway_tablet *tablet); 53 | 54 | void sway_tablet_destroy(struct sway_tablet *tablet); 55 | 56 | void sway_tablet_tool_configure(struct sway_tablet *tablet, 57 | struct wlr_tablet_tool *wlr_tool); 58 | 59 | struct sway_tablet_pad *sway_tablet_pad_create(struct sway_seat *seat, 60 | struct sway_seat_device *device); 61 | 62 | void sway_configure_tablet_pad(struct sway_tablet_pad *tablet_pad); 63 | 64 | void sway_tablet_pad_destroy(struct sway_tablet_pad *tablet_pad); 65 | 66 | void sway_tablet_pad_set_focus(struct sway_tablet_pad *tablet_pad, 67 | struct wlr_surface *surface); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /include/sway/input/text_input_popup.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_INPUT_TEXT_INPUT_POPUP_H 2 | #define _SWAY_INPUT_TEXT_INPUT_POPUP_H 3 | 4 | #include "sway/tree/view.h" 5 | 6 | struct sway_input_popup { 7 | struct sway_input_method_relay *relay; 8 | 9 | struct wlr_scene_tree *scene_tree; 10 | struct sway_popup_desc desc; 11 | struct wlr_input_popup_surface_v2 *popup_surface; 12 | struct wlr_output *fixed_output; 13 | 14 | struct wl_list link; 15 | 16 | struct wl_listener popup_destroy; 17 | struct wl_listener popup_surface_commit; 18 | struct wl_listener popup_surface_map; 19 | struct wl_listener popup_surface_unmap; 20 | 21 | struct wl_listener focused_surface_unmap; 22 | }; 23 | #endif 24 | -------------------------------------------------------------------------------- /include/sway/ipc-json.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_IPC_JSON_H 2 | #define _SWAY_IPC_JSON_H 3 | #include 4 | #include "sway/output.h" 5 | #include "sway/tree/container.h" 6 | #include "sway/input/input-manager.h" 7 | 8 | json_object *ipc_json_get_version(void); 9 | 10 | json_object *ipc_json_get_binding_mode(void); 11 | 12 | json_object *ipc_json_describe_disabled_output(struct sway_output *o); 13 | json_object *ipc_json_describe_non_desktop_output(struct sway_output_non_desktop *o); 14 | json_object *ipc_json_describe_node(struct sway_node *node); 15 | json_object *ipc_json_describe_node_recursive(struct sway_node *node); 16 | json_object *ipc_json_describe_input(struct sway_input_device *device); 17 | json_object *ipc_json_describe_seat(struct sway_seat *seat); 18 | json_object *ipc_json_describe_bar_config(struct bar_config *bar); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/sway/ipc-server.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_IPC_SERVER_H 2 | #define _SWAY_IPC_SERVER_H 3 | #include 4 | #include "sway/config.h" 5 | #include "sway/input/input-manager.h" 6 | #include "sway/tree/container.h" 7 | #include "ipc.h" 8 | 9 | struct sway_server; 10 | 11 | void ipc_init(struct sway_server *server); 12 | 13 | struct sockaddr_un *ipc_user_sockaddr(void); 14 | 15 | void ipc_event_workspace(struct sway_workspace *old, 16 | struct sway_workspace *new, const char *change); 17 | void ipc_event_window(struct sway_container *window, const char *change); 18 | void ipc_event_barconfig_update(struct bar_config *bar); 19 | void ipc_event_bar_state_update(struct bar_config *bar); 20 | void ipc_event_mode(const char *mode, bool pango); 21 | void ipc_event_shutdown(const char *reason); 22 | void ipc_event_binding(struct sway_binding *binding); 23 | void ipc_event_input(const char *change, struct sway_input_device *device); 24 | void ipc_event_output(void); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/sway/layers.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_LAYERS_H 2 | #define _SWAY_LAYERS_H 3 | #include 4 | #include 5 | #include 6 | #include "sway/tree/view.h" 7 | 8 | struct sway_layer_surface { 9 | struct wl_listener map; 10 | struct wl_listener unmap; 11 | struct wl_listener surface_commit; 12 | struct wl_listener output_destroy; 13 | struct wl_listener node_destroy; 14 | struct wl_listener new_popup; 15 | 16 | bool mapped; 17 | 18 | struct wlr_scene_tree *popups; 19 | struct sway_popup_desc desc; 20 | 21 | struct sway_output *output; 22 | struct wlr_scene_layer_surface_v1 *scene; 23 | struct wlr_scene_tree *tree; 24 | struct wlr_layer_surface_v1 *layer_surface; 25 | }; 26 | 27 | struct sway_layer_popup { 28 | struct wlr_xdg_popup *wlr_popup; 29 | struct wlr_scene_tree *scene; 30 | struct sway_layer_surface *toplevel; 31 | 32 | struct wl_listener destroy; 33 | struct wl_listener new_popup; 34 | struct wl_listener commit; 35 | }; 36 | 37 | struct sway_output; 38 | 39 | struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface( 40 | struct wlr_surface *surface); 41 | 42 | void arrange_layers(struct sway_output *output); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/sway/lock.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_LOCK_H 2 | #define _SWAY_LOCK_H 3 | 4 | void arrange_locks(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/sway/scene_descriptor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Across a wayland compositor, there are multiple shells: It can be 3 | * a toplevel, or a layer_shell, or even something more meta like a drag 4 | * icon or highlight indicators when dragging windows around. 5 | * 6 | * This object lets us store values that represent these modes of operation 7 | * and keep track of what object is being represented. 8 | */ 9 | #ifndef _SWAY_SCENE_DESCRIPTOR_H 10 | #define _SWAY_SCENE_DESCRIPTOR_H 11 | #include 12 | 13 | enum sway_scene_descriptor_type { 14 | SWAY_SCENE_DESC_BUFFER_TIMER, 15 | SWAY_SCENE_DESC_NON_INTERACTIVE, 16 | SWAY_SCENE_DESC_CONTAINER, 17 | SWAY_SCENE_DESC_VIEW, 18 | SWAY_SCENE_DESC_LAYER_SHELL, 19 | SWAY_SCENE_DESC_XWAYLAND_UNMANAGED, 20 | SWAY_SCENE_DESC_POPUP, 21 | SWAY_SCENE_DESC_DRAG_ICON, 22 | }; 23 | 24 | bool scene_descriptor_assign(struct wlr_scene_node *node, 25 | enum sway_scene_descriptor_type type, void *data); 26 | 27 | void *scene_descriptor_try_get(struct wlr_scene_node *node, 28 | enum sway_scene_descriptor_type type); 29 | 30 | void scene_descriptor_destroy(struct wlr_scene_node *node, 31 | enum sway_scene_descriptor_type type); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/sway/sway_text_node.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_BUFFER_H 2 | #define _SWAY_BUFFER_H 3 | #include 4 | 5 | struct sway_text_node { 6 | int width; 7 | int max_width; 8 | int height; 9 | int baseline; 10 | bool pango_markup; 11 | float color[4]; 12 | float background[4]; 13 | 14 | struct wlr_scene_node *node; 15 | }; 16 | 17 | struct sway_text_node *sway_text_node_create(struct wlr_scene_tree *parent, 18 | char *text, float color[4], bool pango_markup); 19 | 20 | void sway_text_node_set_color(struct sway_text_node *node, float color[4]); 21 | 22 | void sway_text_node_set_text(struct sway_text_node *node, char *text); 23 | 24 | void sway_text_node_set_max_width(struct sway_text_node *node, int max_width); 25 | 26 | void sway_text_node_set_background(struct sway_text_node *node, float background[4]); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/sway/swaynag.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_SWAYNAG_H 2 | #define _SWAY_SWAYNAG_H 3 | #include 4 | #include "stringop.h" 5 | 6 | struct swaynag_instance { 7 | struct wl_client *client; 8 | struct wl_listener client_destroy; 9 | 10 | const char *args; 11 | int fd[2]; 12 | bool detailed; 13 | }; 14 | 15 | // Spawn swaynag. If swaynag->detailed, then swaynag->fd[1] will left open 16 | // so it can be written to. Call swaynag_show when done writing. This will 17 | // be automatically called by swaynag_log if the instance is not spawned and 18 | // swaynag->detailed is true. 19 | bool swaynag_spawn(const char *swaynag_command, 20 | struct swaynag_instance *swaynag); 21 | 22 | // Write a log message to swaynag->fd[1]. This will fail when swaynag->detailed 23 | // is false. 24 | void swaynag_log(const char *swaynag_command, struct swaynag_instance *swaynag, 25 | const char *fmt, ...) _SWAY_ATTRIB_PRINTF(3, 4); 26 | 27 | // If swaynag->detailed, close swaynag->fd[1] so swaynag displays 28 | void swaynag_show(struct swaynag_instance *swaynag); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/sway/tree/arrange.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_ARRANGE_H 2 | #define _SWAY_ARRANGE_H 3 | 4 | struct sway_output; 5 | struct sway_workspace; 6 | struct sway_container; 7 | struct sway_node; 8 | 9 | void arrange_container(struct sway_container *container); 10 | 11 | void arrange_workspace(struct sway_workspace *workspace); 12 | 13 | void arrange_output(struct sway_output *output); 14 | 15 | void arrange_root(void); 16 | 17 | void arrange_node(struct sway_node *node); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/sway/xdg_decoration.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_XDG_DECORATION_H 2 | #define _SWAY_XDG_DECORATION_H 3 | 4 | #include 5 | 6 | struct sway_xdg_decoration { 7 | struct wlr_xdg_toplevel_decoration_v1 *wlr_xdg_decoration; 8 | struct wl_list link; 9 | 10 | struct sway_view *view; 11 | 12 | struct wl_listener destroy; 13 | struct wl_listener request_mode; 14 | }; 15 | 16 | struct sway_xdg_decoration *xdg_decoration_from_surface( 17 | struct wlr_surface *surface); 18 | 19 | void set_xdg_decoration_mode(struct sway_xdg_decoration *deco); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/sway/xwayland.h: -------------------------------------------------------------------------------- 1 | #ifndef SWAY_XWAYLAND_H 2 | #define SWAY_XWAYLAND_H 3 | 4 | #include 5 | #include 6 | 7 | enum atom_name { 8 | NET_WM_WINDOW_TYPE_NORMAL, 9 | NET_WM_WINDOW_TYPE_DIALOG, 10 | NET_WM_WINDOW_TYPE_UTILITY, 11 | NET_WM_WINDOW_TYPE_TOOLBAR, 12 | NET_WM_WINDOW_TYPE_SPLASH, 13 | NET_WM_WINDOW_TYPE_MENU, 14 | NET_WM_WINDOW_TYPE_DROPDOWN_MENU, 15 | NET_WM_WINDOW_TYPE_POPUP_MENU, 16 | NET_WM_WINDOW_TYPE_TOOLTIP, 17 | NET_WM_WINDOW_TYPE_NOTIFICATION, 18 | NET_WM_STATE_MODAL, 19 | ATOM_LAST, 20 | }; 21 | 22 | struct sway_xwayland { 23 | struct wlr_xwayland *wlr_xwayland; 24 | struct wlr_xcursor_manager *xcursor_manager; 25 | 26 | xcb_atom_t atoms[ATOM_LAST]; 27 | }; 28 | 29 | void handle_xwayland_ready(struct wl_listener *listener, void *data); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/swaybar/i3bar.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_I3BAR_H 2 | #define _SWAYBAR_I3BAR_H 3 | 4 | #include "input.h" 5 | #include "status_line.h" 6 | 7 | struct i3bar_block { 8 | struct wl_list link; // status_link::blocks 9 | int ref_count; 10 | char *full_text, *short_text, *align, *min_width_str; 11 | bool urgent; 12 | uint32_t color; 13 | bool color_set; 14 | int min_width; 15 | char *name, *instance; 16 | bool separator; 17 | int separator_block_width; 18 | bool markup; 19 | // Airblader features 20 | uint32_t background; 21 | uint32_t border; 22 | bool border_set; 23 | int border_top; 24 | int border_bottom; 25 | int border_left; 26 | int border_right; 27 | }; 28 | 29 | void i3bar_block_unref(struct i3bar_block *block); 30 | bool i3bar_handle_readable(struct status_line *status); 31 | enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, 32 | struct i3bar_block *block, double x, double y, double rx, double ry, 33 | double w, double h, int scale, uint32_t button, bool released); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/swaybar/image.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_IMAGE_H 2 | #define _SWAYBAR_IMAGE_H 3 | #include 4 | 5 | cairo_surface_t *load_image(const char *path); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /include/swaybar/ipc.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_IPC_H 2 | #define _SWAYBAR_IPC_H 3 | #include 4 | #include "swaybar/bar.h" 5 | 6 | bool ipc_initialize(struct swaybar *bar); 7 | bool handle_ipc_readable(struct swaybar *bar); 8 | bool ipc_get_workspaces(struct swaybar *bar); 9 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws); 10 | void ipc_execute_binding(struct swaybar *bar, struct swaybar_binding *bind); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /include/swaybar/render.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_RENDER_H 2 | #define _SWAYBAR_RENDER_H 3 | 4 | struct swaybar_output; 5 | 6 | void render_frame(struct swaybar_output *output); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /include/swaybar/status_line.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_STATUS_LINE_H 2 | #define _SWAYBAR_STATUS_LINE_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "bar.h" 8 | 9 | enum status_protocol { 10 | PROTOCOL_UNDEF, 11 | PROTOCOL_ERROR, 12 | PROTOCOL_TEXT, 13 | PROTOCOL_I3BAR, 14 | }; 15 | 16 | struct status_line { 17 | struct swaybar *bar; 18 | 19 | pid_t pid; 20 | int read_fd, write_fd; 21 | FILE *read, *write; 22 | 23 | enum status_protocol protocol; 24 | const char *text; 25 | struct wl_list blocks; // i3bar_block::link 26 | 27 | int stop_signal; 28 | int cont_signal; 29 | 30 | bool click_events; 31 | bool float_event_coords; 32 | bool clicked; 33 | char *buffer; 34 | size_t buffer_size; 35 | size_t buffer_index; 36 | bool started; 37 | bool expecting_comma; 38 | json_tokener *tokener; 39 | }; 40 | 41 | struct status_line *status_line_init(char *cmd); 42 | void status_error(struct status_line *status, const char *text); 43 | bool status_handle_readable(struct status_line *status); 44 | void status_line_free(struct status_line *status); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /include/swaybar/tray/host.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_TRAY_HOST_H 2 | #define _SWAYBAR_TRAY_HOST_H 3 | 4 | #include 5 | 6 | struct swaybar_tray; 7 | 8 | struct swaybar_host { 9 | struct swaybar_tray *tray; 10 | char *service; 11 | char *watcher_interface; 12 | }; 13 | 14 | bool init_host(struct swaybar_host *host, char *protocol, struct swaybar_tray *tray); 15 | void finish_host(struct swaybar_host *host); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/swaybar/tray/icon.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_TRAY_ICON_H 2 | #define _SWAYBAR_TRAY_ICON_H 3 | 4 | #include "list.h" 5 | 6 | struct icon_theme_subdir { 7 | char *name; 8 | int size; 9 | 10 | enum { 11 | THRESHOLD, 12 | SCALABLE, 13 | FIXED 14 | } type; 15 | 16 | int max_size; 17 | int min_size; 18 | int threshold; 19 | }; 20 | 21 | struct icon_theme { 22 | char *name; 23 | char *comment; 24 | list_t *inherits; // char * 25 | list_t *directories; // char * 26 | 27 | char *dir; 28 | list_t *subdirs; // struct icon_theme_subdir * 29 | }; 30 | 31 | void init_themes(list_t **themes, list_t **basedirs); 32 | void finish_themes(list_t *themes, list_t *basedirs); 33 | 34 | /* 35 | * Finds an icon of a specified size given a list of themes and base directories. 36 | * If the icon is found, the pointers min_size & max_size are set to minimum & 37 | * maximum size that the icon can be scaled to, respectively. 38 | * Returns: path of icon (which should be freed), or NULL if the icon is not found. 39 | */ 40 | char *find_icon(list_t *themes, list_t *basedirs, char *name, int size, 41 | char *theme, int *min_size, int *max_size); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/swaybar/tray/item.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_TRAY_ITEM_H 2 | #define _SWAYBAR_TRAY_ITEM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "swaybar/tray/tray.h" 9 | #include "list.h" 10 | 11 | struct swaybar_output; 12 | 13 | struct swaybar_pixmap { 14 | int size; 15 | unsigned char pixels[]; 16 | }; 17 | 18 | struct swaybar_sni_slot { 19 | struct wl_list link; // swaybar_sni::slots 20 | struct swaybar_sni *sni; 21 | const char *prop; 22 | const char *type; 23 | void *dest; 24 | sd_bus_slot *slot; 25 | }; 26 | 27 | struct swaybar_sni { 28 | // icon properties 29 | struct swaybar_tray *tray; 30 | cairo_surface_t *icon; 31 | int min_size; 32 | int max_size; 33 | int target_size; 34 | 35 | // dbus properties 36 | char *watcher_id; 37 | char *service; 38 | char *path; 39 | char *interface; 40 | 41 | char *status; 42 | char *icon_name; 43 | list_t *icon_pixmap; // struct swaybar_pixmap * 44 | char *attention_icon_name; 45 | list_t *attention_icon_pixmap; // struct swaybar_pixmap * 46 | bool item_is_menu; 47 | char *menu; 48 | char *icon_theme_path; // non-standard KDE property 49 | 50 | struct wl_list slots; // swaybar_sni_slot::link 51 | }; 52 | 53 | struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray); 54 | void destroy_sni(struct swaybar_sni *sni); 55 | uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x, 56 | struct swaybar_sni *sni); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/swaybar/tray/tray.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_TRAY_TRAY_H 2 | #define _SWAYBAR_TRAY_TRAY_H 3 | 4 | #include "config.h" 5 | #if HAVE_LIBSYSTEMD 6 | #include 7 | #elif HAVE_LIBELOGIND 8 | #include 9 | #elif HAVE_BASU 10 | #include 11 | #endif 12 | #include 13 | #include 14 | #include "swaybar/tray/host.h" 15 | #include "list.h" 16 | 17 | struct swaybar; 18 | struct swaybar_output; 19 | struct swaybar_watcher; 20 | 21 | struct swaybar_tray { 22 | struct swaybar *bar; 23 | 24 | int fd; 25 | sd_bus *bus; 26 | 27 | struct swaybar_host host_xdg; 28 | struct swaybar_host host_kde; 29 | list_t *items; // struct swaybar_sni * 30 | struct swaybar_watcher *watcher_xdg; 31 | struct swaybar_watcher *watcher_kde; 32 | 33 | list_t *basedirs; // char * 34 | list_t *themes; // struct swaybar_theme * 35 | }; 36 | 37 | struct swaybar_tray *create_tray(struct swaybar *bar); 38 | void destroy_tray(struct swaybar_tray *tray); 39 | void tray_in(int fd, short mask, void *data); 40 | uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/swaybar/tray/watcher.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYBAR_TRAY_WATCHER_H 2 | #define _SWAYBAR_TRAY_WATCHER_H 3 | 4 | #include "swaybar/tray/tray.h" 5 | #include "list.h" 6 | 7 | struct swaybar_watcher { 8 | char *interface; 9 | sd_bus *bus; 10 | list_t *hosts; 11 | list_t *items; 12 | int version; 13 | }; 14 | 15 | struct swaybar_watcher *create_watcher(char *protocol, sd_bus *bus); 16 | void destroy_watcher(struct swaybar_watcher *watcher); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /include/swaynag/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYNAG_CONFIG_H 2 | #define _SWAYNAG_CONFIG_H 3 | #include "swaynag/swaynag.h" 4 | #include "list.h" 5 | 6 | int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, 7 | list_t *types, struct swaynag_type *type, char **config, bool *debug); 8 | 9 | char *swaynag_get_config_path(void); 10 | 11 | int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /include/swaynag/render.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYNAG_RENDER_H 2 | #define _SWAYNAG_RENDER_H 3 | #include "swaynag/swaynag.h" 4 | 5 | void render_frame(struct swaynag *swaynag); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /include/swaynag/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAYNAG_TYPES_H 2 | #define _SWAYNAG_TYPES_H 3 | 4 | #include 5 | #include 6 | #include "list.h" 7 | 8 | struct swaynag_type { 9 | char *name; 10 | 11 | PangoFontDescription *font_description; 12 | char *output; 13 | uint32_t anchors; 14 | int32_t layer; // enum zwlr_layer_shell_v1_layer or -1 if unset 15 | 16 | // Colors 17 | uint32_t button_text; 18 | uint32_t button_background; 19 | uint32_t details_background; 20 | uint32_t background; 21 | uint32_t text; 22 | uint32_t border; 23 | uint32_t border_bottom; 24 | 25 | // Sizing 26 | ssize_t bar_border_thickness; 27 | ssize_t message_padding; 28 | ssize_t details_border_thickness; 29 | ssize_t button_border_thickness; 30 | ssize_t button_gap; 31 | ssize_t button_gap_close; 32 | ssize_t button_margin_right; 33 | ssize_t button_padding; 34 | }; 35 | 36 | struct swaynag_type *swaynag_type_new(const char *name); 37 | 38 | void swaynag_types_add_default(list_t *types); 39 | 40 | struct swaynag_type *swaynag_type_get(list_t *types, char *name); 41 | 42 | struct swaynag_type *swaynag_type_clone(struct swaynag_type *type); 43 | 44 | void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src); 45 | 46 | void swaynag_type_free(struct swaynag_type *type); 47 | 48 | void swaynag_types_free(list_t *types); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/util.h: -------------------------------------------------------------------------------- 1 | #ifndef _SWAY_UTIL_H 2 | #define _SWAY_UTIL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | enum movement_unit { 9 | MOVEMENT_UNIT_PX, 10 | MOVEMENT_UNIT_PPT, 11 | MOVEMENT_UNIT_DEFAULT, 12 | MOVEMENT_UNIT_INVALID, 13 | }; 14 | 15 | struct movement_amount { 16 | int amount; 17 | enum movement_unit unit; 18 | }; 19 | 20 | /* 21 | * Parse units such as "px" or "ppt" 22 | */ 23 | enum movement_unit parse_movement_unit(const char *unit); 24 | 25 | /* 26 | * Parse arguments such as "10", "10px" or "10 px". 27 | * Returns the number of arguments consumed. 28 | */ 29 | int parse_movement_amount(int argc, char **argv, 30 | struct movement_amount *amount); 31 | 32 | /** 33 | * Wrap i into the range [0, max] 34 | */ 35 | int wrap(int i, int max); 36 | 37 | /** 38 | * Given a string that represents an RGB(A) color, result will be set to a 39 | * uint32_t version of the color, as long as it is valid. If it is invalid, 40 | * then false will be returned and result will be untouched. 41 | */ 42 | bool parse_color(const char *color, uint32_t *result); 43 | 44 | void color_to_rgba(float dest[static 4], uint32_t color); 45 | 46 | /** 47 | * Given a string that represents a boolean, return the boolean value. This 48 | * function also takes in the current boolean value to support toggling. If 49 | * toggling is not desired, pass in true for current so that toggling values 50 | * get parsed as not true. 51 | */ 52 | bool parse_boolean(const char *boolean, bool current); 53 | 54 | /** 55 | * Given a string that represents a floating point value, return a float. 56 | * Returns NAN on error. 57 | */ 58 | float parse_float(const char *value); 59 | 60 | const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel); 61 | 62 | bool sway_set_cloexec(int fd, bool cloexec); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('default-wallpaper', type: 'boolean', value: true, description: 'Install the default wallpaper.') 2 | option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') 3 | option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') 4 | option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') 5 | option('swaybar', type: 'boolean', value: true, description: 'Enable support for swaybar') 6 | option('swaynag', type: 'boolean', value: true, description: 'Enable support for swaynag') 7 | option('tray', type: 'feature', value: 'auto', description: 'Enable support for swaybar tray') 8 | option('gdk-pixbuf', type: 'feature', value: 'auto', description: 'Enable support for more image formats in swaybar tray') 9 | option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages') 10 | option('sd-bus-provider', type: 'combo', choices: ['auto', 'libsystemd', 'libelogind', 'basu'], value: 'auto', description: 'Provider of the sd-bus library') 11 | -------------------------------------------------------------------------------- /protocols/meson.build: -------------------------------------------------------------------------------- 1 | wl_protocol_dir = wayland_protos.get_variable('pkgdatadir') 2 | 3 | wayland_scanner_dep = dependency('wayland-scanner', native: true) 4 | wayland_scanner = find_program( 5 | wayland_scanner_dep.get_variable('wayland_scanner'), 6 | native: true, 7 | ) 8 | 9 | protocols = [ 10 | wl_protocol_dir / 'stable/tablet/tablet-v2.xml', 11 | wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml', 12 | wl_protocol_dir / 'staging/content-type/content-type-v1.xml', 13 | wl_protocol_dir / 'staging/cursor-shape/cursor-shape-v1.xml', 14 | wl_protocol_dir / 'staging/ext-foreign-toplevel-list/ext-foreign-toplevel-list-v1.xml', 15 | wl_protocol_dir / 'staging/ext-image-capture-source/ext-image-capture-source-v1.xml', 16 | wl_protocol_dir / 'staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml', 17 | wl_protocol_dir / 'staging/tearing-control/tearing-control-v1.xml', 18 | wl_protocol_dir / 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml', 19 | wl_protocol_dir / 'unstable/pointer-constraints/pointer-constraints-unstable-v1.xml', 20 | wl_protocol_dir / 'unstable/xdg-output/xdg-output-unstable-v1.xml', 21 | 'wlr-layer-shell-unstable-v1.xml', 22 | 'idle.xml', 23 | 'wlr-output-power-management-unstable-v1.xml', 24 | ] 25 | 26 | wl_protos_src = [] 27 | 28 | foreach xml : protocols 29 | wl_protos_src += custom_target( 30 | xml.underscorify() + '_c', 31 | input: xml, 32 | output: '@BASENAME@-protocol.c', 33 | command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'], 34 | ) 35 | wl_protos_src += custom_target( 36 | xml.underscorify() + '_server_h', 37 | input: xml, 38 | output: '@BASENAME@-protocol.h', 39 | command: [wayland_scanner, 'server-header', '@INPUT@', '@OUTPUT@'], 40 | ) 41 | wl_protos_src += custom_target( 42 | xml.underscorify() + '_client_h', 43 | input: xml, 44 | output: '@BASENAME@-client-protocol.h', 45 | command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'], 46 | ) 47 | endforeach 48 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -eu 2 | 3 | prev=$(git describe --tags --abbrev=0) 4 | next=$(meson rewrite kwargs info project / | jq -r '.kwargs["project#/"].version') 5 | 6 | case "$next" in 7 | *-dev) 8 | echo "This is a development version" 9 | exit 1 10 | ;; 11 | esac 12 | 13 | if [ "$prev" = "$next" ]; then 14 | echo "Version not bumped in meson.build" 15 | exit 1 16 | fi 17 | 18 | if ! git diff-index --quiet HEAD -- meson.build; then 19 | echo "meson.build not committed" 20 | exit 1 21 | fi 22 | 23 | shortlog="$(git shortlog --no-merges "$prev..")" 24 | (echo "sway $next"; echo ""; echo "$shortlog") | git tag "$next" -ase -F - 25 | 26 | prefix=sway-$next 27 | archive=$prefix.tar.gz 28 | git archive --prefix="$prefix/" -o "$archive" "$next" 29 | gpg --output "$archive".sig --detach-sig "$archive" 30 | 31 | git push --follow-tags 32 | gh release create "sway $next" -t "$next" -n "" -d "$archive" "$archive.sig" 33 | -------------------------------------------------------------------------------- /sway.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Sway 3 | Comment=An i3-compatible Wayland compositor 4 | Exec=sway 5 | Type=Application 6 | DesktopNames=sway;wlroots 7 | -------------------------------------------------------------------------------- /sway/commands/allow_tearing.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/config.h" 3 | #include "sway/tree/view.h" 4 | #include "util.h" 5 | 6 | struct cmd_results *cmd_allow_tearing(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "allow_tearing", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | 12 | struct sway_container *container = config->handler_context.container; 13 | if (!container || !container->view) { 14 | return cmd_results_new(CMD_INVALID, "Tearing can only be allowed on views"); 15 | } 16 | 17 | bool wants_tearing = parse_boolean(argv[0], true); 18 | 19 | struct sway_view *view = container->view; 20 | view->tearing_mode = wants_tearing ? TEARING_OVERRIDE_TRUE : 21 | TEARING_OVERRIDE_FALSE; 22 | 23 | return cmd_results_new(CMD_SUCCESS, NULL); 24 | } 25 | -------------------------------------------------------------------------------- /sway/commands/assign.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "sway/criteria.h" 5 | #include "list.h" 6 | #include "log.h" 7 | #include "stringop.h" 8 | 9 | struct cmd_results *cmd_assign(int argc, char **argv) { 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "assign", EXPECTED_AT_LEAST, 2))) { 12 | return error; 13 | } 14 | 15 | // Create criteria 16 | char *err_str = NULL; 17 | struct criteria *criteria = criteria_parse(argv[0], &err_str); 18 | if (!criteria) { 19 | error = cmd_results_new(CMD_INVALID, "%s", err_str); 20 | free(err_str); 21 | return error; 22 | } 23 | 24 | --argc; ++argv; 25 | 26 | if (has_prefix(*argv, "→")) { 27 | if (argc < 2) { 28 | free(criteria); 29 | return cmd_results_new(CMD_INVALID, "Missing workspace"); 30 | } 31 | --argc; 32 | ++argv; 33 | } 34 | 35 | if (strcmp(*argv, "output") == 0) { 36 | criteria->type = CT_ASSIGN_OUTPUT; 37 | --argc; ++argv; 38 | } else { 39 | if (strcmp(*argv, "workspace") == 0) { 40 | --argc; ++argv; 41 | } 42 | if (strcmp(*argv, "number") == 0) { 43 | --argc; ++argv; 44 | if (argv[0][0] < '0' || argv[0][0] > '9') { 45 | free(criteria); 46 | return cmd_results_new(CMD_INVALID, 47 | "Invalid workspace number '%s'", argv[0]); 48 | } 49 | criteria->type = CT_ASSIGN_WORKSPACE_NUMBER; 50 | } else { 51 | criteria->type = CT_ASSIGN_WORKSPACE; 52 | } 53 | } 54 | 55 | criteria->target = join_args(argv, argc); 56 | 57 | list_add(config->criteria, criteria); 58 | sway_log(SWAY_DEBUG, "assign: '%s' -> '%s' added", criteria->raw, 59 | criteria->target); 60 | 61 | return cmd_results_new(CMD_SUCCESS, NULL); 62 | } 63 | -------------------------------------------------------------------------------- /sway/commands/bar/binding_mode_indicator.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, 10 | "binding_mode_indicator", EXPECTED_EQUAL_TO, 1))) { 11 | return error; 12 | } 13 | config->current_bar->binding_mode_indicator = 14 | parse_boolean(argv[0], config->current_bar->binding_mode_indicator); 15 | if (config->current_bar->binding_mode_indicator) { 16 | sway_log(SWAY_DEBUG, "Enabling binding mode indicator on bar: %s", 17 | config->current_bar->id); 18 | } else { 19 | sway_log(SWAY_DEBUG, "Disabling binding mode indicator on bar: %s", 20 | config->current_bar->id); 21 | } 22 | return cmd_results_new(CMD_SUCCESS, NULL); 23 | } 24 | -------------------------------------------------------------------------------- /sway/commands/bar/font.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | #include "stringop.h" 5 | 6 | struct cmd_results *bar_cmd_font(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | char *font = join_args(argv, argc); 12 | free(config->current_bar->font); 13 | 14 | if (has_prefix(font, "pango:")) { 15 | if (config->current_bar->pango_markup == PANGO_MARKUP_DEFAULT) { 16 | config->current_bar->pango_markup = true; 17 | } 18 | config->current_bar->font = strdup(font + 6); 19 | } else { 20 | if (config->current_bar->pango_markup == PANGO_MARKUP_DEFAULT) { 21 | config->current_bar->pango_markup = false; 22 | } 23 | config->current_bar->font = strdup(font); 24 | } 25 | 26 | free(font); 27 | sway_log(SWAY_DEBUG, "Settings font '%s' for bar: %s", 28 | config->current_bar->font, config->current_bar->id); 29 | return cmd_results_new(CMD_SUCCESS, NULL); 30 | } 31 | -------------------------------------------------------------------------------- /sway/commands/bar/gaps.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "sway/commands.h" 5 | #include "sway/ipc-server.h" 6 | #include "log.h" 7 | 8 | struct cmd_results *bar_cmd_gaps(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_MOST, 4))) { 14 | return error; 15 | } 16 | 17 | int top = 0, right = 0, bottom = 0, left = 0; 18 | 19 | for (int i = 0; i < argc; i++) { 20 | char *end; 21 | int amount = strtol(argv[i], &end, 10); 22 | if (strlen(end) && strcasecmp(end, "px") != 0) { 23 | return cmd_results_new(CMD_INVALID, 24 | "Expected 'bar [] gaps | " 25 | " | '"); 26 | } 27 | 28 | if (i == 0) { 29 | top = amount; 30 | } 31 | if (i == 0 || i == 1) { 32 | right = amount; 33 | } 34 | if (i == 0 || i == 2) { 35 | bottom = amount; 36 | } 37 | if (i == 0 || i == 1 || i == 3) { 38 | left = amount; 39 | } 40 | } 41 | 42 | config->current_bar->gaps.top = top; 43 | config->current_bar->gaps.right = right; 44 | config->current_bar->gaps.bottom = bottom; 45 | config->current_bar->gaps.left = left; 46 | 47 | sway_log(SWAY_DEBUG, "Setting bar gaps to %d %d %d %d on bar: %s", 48 | config->current_bar->gaps.top, config->current_bar->gaps.right, 49 | config->current_bar->gaps.bottom, config->current_bar->gaps.left, 50 | config->current_bar->id); 51 | 52 | if (!config->reading) { 53 | ipc_event_barconfig_update(config->current_bar); 54 | } 55 | 56 | return cmd_results_new(CMD_SUCCESS, NULL); 57 | } 58 | -------------------------------------------------------------------------------- /sway/commands/bar/height.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | 6 | struct cmd_results *bar_cmd_height(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | int height = atoi(argv[0]); 12 | if (height < 0) { 13 | return cmd_results_new(CMD_INVALID, 14 | "Invalid height value: %s", argv[0]); 15 | } 16 | config->current_bar->height = height; 17 | sway_log(SWAY_DEBUG, "Setting bar height to %d on bar: %s", 18 | height, config->current_bar->id); 19 | return cmd_results_new(CMD_SUCCESS, NULL); 20 | } 21 | -------------------------------------------------------------------------------- /sway/commands/bar/icon_theme.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "config.h" 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "log.h" 6 | 7 | struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) { 8 | #if HAVE_TRAY 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "icon_theme", EXPECTED_EQUAL_TO, 1))) { 11 | return error; 12 | } 13 | 14 | sway_log(SWAY_DEBUG, "[Bar %s] Setting icon theme to %s", 15 | config->current_bar->id, argv[0]); 16 | free(config->current_bar->icon_theme); 17 | config->current_bar->icon_theme = strdup(argv[0]); 18 | return cmd_results_new(CMD_SUCCESS, NULL); 19 | #else 20 | return cmd_results_new(CMD_INVALID, 21 | "Sway has been compiled without tray support"); 22 | #endif 23 | } 24 | -------------------------------------------------------------------------------- /sway/commands/bar/id.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | 5 | struct cmd_results *bar_cmd_id(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | 11 | const char *name = argv[0]; 12 | const char *oldname = config->current_bar->id; 13 | if (strcmp(name, oldname) == 0) { 14 | return cmd_results_new(CMD_SUCCESS, NULL); // NOP 15 | } else if (strcmp(name, "id") == 0) { 16 | return cmd_results_new(CMD_INVALID, "id cannot be 'id'"); 17 | } 18 | // check if id is used by a previously defined bar 19 | for (int i = 0; i < config->bars->length; ++i) { 20 | struct bar_config *find = config->bars->items[i]; 21 | if (strcmp(name, find->id) == 0 && config->current_bar != find) { 22 | return cmd_results_new(CMD_FAILURE, 23 | "Id '%s' already defined for another bar. Id unchanged (%s).", 24 | name, oldname); 25 | } 26 | } 27 | 28 | sway_log(SWAY_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name); 29 | 30 | // free old bar id 31 | free(config->current_bar->id); 32 | config->current_bar->id = strdup(name); 33 | return cmd_results_new(CMD_SUCCESS, NULL); 34 | } 35 | -------------------------------------------------------------------------------- /sway/commands/bar/modifier.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/input/keyboard.h" 4 | #include "log.h" 5 | #include "stringop.h" 6 | 7 | struct cmd_results *bar_cmd_modifier(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | 13 | uint32_t mod = 0; 14 | if (strcmp(argv[0], "none") != 0) { 15 | list_t *split = split_string(argv[0], "+"); 16 | for (int i = 0; i < split->length; ++i) { 17 | uint32_t tmp_mod; 18 | if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) { 19 | mod |= tmp_mod; 20 | } else if (strcmp(split->items[i], "none") == 0) { 21 | error = cmd_results_new(CMD_INVALID, 22 | "none cannot be used along with other modifiers"); 23 | list_free_items_and_destroy(split); 24 | return error; 25 | } else { 26 | error = cmd_results_new(CMD_INVALID, 27 | "Unknown modifier '%s'", (char *)split->items[i]); 28 | list_free_items_and_destroy(split); 29 | return error; 30 | } 31 | } 32 | list_free_items_and_destroy(split); 33 | } 34 | config->current_bar->modifier = mod; 35 | sway_log(SWAY_DEBUG, 36 | "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); 37 | return cmd_results_new(CMD_SUCCESS, NULL); 38 | } 39 | -------------------------------------------------------------------------------- /sway/commands/bar/output.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "list.h" 5 | #include "log.h" 6 | 7 | struct cmd_results *bar_cmd_output(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | 13 | const char *output = argv[0]; 14 | list_t *outputs = config->current_bar->outputs; 15 | if (!outputs) { 16 | outputs = create_list(); 17 | config->current_bar->outputs = outputs; 18 | } 19 | 20 | bool add_output = true; 21 | if (strcmp("*", output) == 0) { 22 | // remove all previous defined outputs and replace with '*' 23 | while (outputs->length) { 24 | free(outputs->items[0]); 25 | list_del(outputs, 0); 26 | } 27 | } else { 28 | // only add output if not already defined, if the list has '*', remove 29 | // it, in favor of a manual list 30 | for (int i = 0; i < outputs->length; ++i) { 31 | const char *find = outputs->items[i]; 32 | if (strcmp("*", find) == 0) { 33 | free(outputs->items[i]); 34 | list_del(outputs, i); 35 | } else if (strcmp(output, find) == 0) { 36 | add_output = false; 37 | break; 38 | } 39 | } 40 | } 41 | 42 | if (add_output) { 43 | list_add(outputs, strdup(output)); 44 | sway_log(SWAY_DEBUG, "Adding bar: '%s' to output '%s'", 45 | config->current_bar->id, output); 46 | } 47 | return cmd_results_new(CMD_SUCCESS, NULL); 48 | } 49 | -------------------------------------------------------------------------------- /sway/commands/bar/pango_markup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | config->current_bar->pango_markup = 13 | parse_boolean(argv[0], config->current_bar->pango_markup); 14 | if (config->current_bar->pango_markup) { 15 | sway_log(SWAY_DEBUG, "Enabling pango markup for bar: %s", 16 | config->current_bar->id); 17 | } else { 18 | sway_log(SWAY_DEBUG, "Disabling pango markup for bar: %s", 19 | config->current_bar->id); 20 | } 21 | return cmd_results_new(CMD_SUCCESS, NULL); 22 | } 23 | -------------------------------------------------------------------------------- /sway/commands/bar/position.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | 6 | struct cmd_results *bar_cmd_position(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | char *valid[] = { "top", "bottom" }; 12 | for (size_t i = 0; i < sizeof(valid) / sizeof(valid[0]); ++i) { 13 | if (strcasecmp(valid[i], argv[0]) == 0) { 14 | sway_log(SWAY_DEBUG, "Setting bar position '%s' for bar: %s", 15 | argv[0], config->current_bar->id); 16 | free(config->current_bar->position); 17 | config->current_bar->position = strdup(argv[0]); 18 | return cmd_results_new(CMD_SUCCESS, NULL); 19 | } 20 | } 21 | return cmd_results_new(CMD_INVALID, "Invalid value %s", argv[0]); 22 | } 23 | -------------------------------------------------------------------------------- /sway/commands/bar/separator_symbol.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | 5 | struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "separator_symbol", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | free(config->current_bar->separator_symbol); 11 | config->current_bar->separator_symbol = strdup(argv[0]); 12 | sway_log(SWAY_DEBUG, "Settings separator_symbol '%s' for bar: %s", 13 | config->current_bar->separator_symbol, config->current_bar->id); 14 | return cmd_results_new(CMD_SUCCESS, NULL); 15 | } 16 | -------------------------------------------------------------------------------- /sway/commands/bar/status_command.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | #include "stringop.h" 5 | 6 | struct cmd_results *bar_cmd_status_command(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "status_command", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | free(config->current_bar->status_command); 12 | config->current_bar->status_command = NULL; 13 | 14 | char *new_command = join_args(argv, argc); 15 | if (strcmp(new_command, "-") != 0) { 16 | config->current_bar->status_command = new_command; 17 | sway_log(SWAY_DEBUG, "Feeding bar with status command: %s", 18 | config->current_bar->status_command); 19 | } else { 20 | free(new_command); 21 | } 22 | return cmd_results_new(CMD_SUCCESS, NULL); 23 | } 24 | -------------------------------------------------------------------------------- /sway/commands/bar/status_edge_padding.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | 6 | struct cmd_results *bar_cmd_status_edge_padding(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "status_edge_padding", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | char *end; 12 | int padding = strtol(argv[0], &end, 10); 13 | if (strlen(end) || padding < 0) { 14 | return cmd_results_new(CMD_INVALID, 15 | "Padding must be a positive integer"); 16 | } 17 | config->current_bar->status_edge_padding = padding; 18 | sway_log(SWAY_DEBUG, "Status edge padding on bar %s: %d", 19 | config->current_bar->id, config->current_bar->status_edge_padding); 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/bar/status_padding.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | 6 | struct cmd_results *bar_cmd_status_padding(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "status_padding", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | char *end; 12 | int padding = strtol(argv[0], &end, 10); 13 | if (strlen(end) || padding < 0) { 14 | return cmd_results_new(CMD_INVALID, 15 | "Padding must be a positive integer"); 16 | } 17 | config->current_bar->status_padding = padding; 18 | sway_log(SWAY_DEBUG, "Status padding on bar %s: %d", 19 | config->current_bar->id, config->current_bar->status_padding); 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/bar/strip_workspace_name.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *bar_cmd_strip_workspace_name(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, 10 | "strip_workspace_name", EXPECTED_EQUAL_TO, 1))) { 11 | return error; 12 | } 13 | 14 | config->current_bar->strip_workspace_name = 15 | parse_boolean(argv[0], config->current_bar->strip_workspace_name); 16 | 17 | if (config->current_bar->strip_workspace_name) { 18 | config->current_bar->strip_workspace_numbers = false; 19 | 20 | sway_log(SWAY_DEBUG, "Stripping workspace name on bar: %s", 21 | config->current_bar->id); 22 | } else { 23 | sway_log(SWAY_DEBUG, "Enabling workspace name on bar: %s", 24 | config->current_bar->id); 25 | } 26 | 27 | return cmd_results_new(CMD_SUCCESS, NULL); 28 | } 29 | -------------------------------------------------------------------------------- /sway/commands/bar/strip_workspace_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, 10 | "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) { 11 | return error; 12 | } 13 | 14 | config->current_bar->strip_workspace_numbers = 15 | parse_boolean(argv[0], config->current_bar->strip_workspace_numbers); 16 | 17 | if (config->current_bar->strip_workspace_numbers) { 18 | config->current_bar->strip_workspace_name = false; 19 | 20 | sway_log(SWAY_DEBUG, "Stripping workspace numbers on bar: %s", 21 | config->current_bar->id); 22 | } else { 23 | sway_log(SWAY_DEBUG, "Enabling workspace numbers on bar: %s", 24 | config->current_bar->id); 25 | } 26 | 27 | return cmd_results_new(CMD_SUCCESS, NULL); 28 | } 29 | -------------------------------------------------------------------------------- /sway/commands/bar/swaybar_command.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | #include "stringop.h" 5 | 6 | struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "swaybar_command", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | free(config->current_bar->swaybar_command); 12 | config->current_bar->swaybar_command = join_args(argv, argc); 13 | sway_log(SWAY_DEBUG, "Using custom swaybar command: %s", 14 | config->current_bar->swaybar_command); 15 | return cmd_results_new(CMD_SUCCESS, NULL); 16 | } 17 | -------------------------------------------------------------------------------- /sway/commands/bar/tray_output.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "config.h" 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "list.h" 6 | #include "log.h" 7 | 8 | struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { 9 | #if HAVE_TRAY 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "tray_output", EXPECTED_EQUAL_TO, 1))) { 12 | return error; 13 | } 14 | 15 | list_t *outputs = config->current_bar->tray_outputs; 16 | if (!outputs) { 17 | config->current_bar->tray_outputs = outputs = create_list(); 18 | } 19 | 20 | if (strcmp(argv[0], "none") == 0) { 21 | sway_log(SWAY_DEBUG, "Hiding tray on bar: %s", config->current_bar->id); 22 | for (int i = 0; i < outputs->length; ++i) { 23 | free(outputs->items[i]); 24 | } 25 | outputs->length = 0; 26 | } else if (strcmp(argv[0], "*") == 0) { 27 | sway_log(SWAY_DEBUG, "Showing tray on all outputs for bar: %s", 28 | config->current_bar->id); 29 | while (outputs->length) { 30 | free(outputs->items[0]); 31 | list_del(outputs, 0); 32 | } 33 | return cmd_results_new(CMD_SUCCESS, NULL); 34 | } else { 35 | sway_log(SWAY_DEBUG, "Showing tray on output '%s' for bar: %s", argv[0], 36 | config->current_bar->id); 37 | if (outputs->length == 1 && strcmp(outputs->items[0], "none") == 0) { 38 | free(outputs->items[0]); 39 | list_del(outputs, 0); 40 | } 41 | } 42 | list_add(outputs, strdup(argv[0])); 43 | 44 | return cmd_results_new(CMD_SUCCESS, NULL); 45 | #else 46 | return cmd_results_new(CMD_INVALID, 47 | "Sway has been compiled without tray support"); 48 | #endif 49 | } 50 | -------------------------------------------------------------------------------- /sway/commands/bar/tray_padding.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "config.h" 4 | #include "sway/commands.h" 5 | #include "sway/config.h" 6 | #include "log.h" 7 | 8 | struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { 9 | #if HAVE_TRAY 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_LEAST, 1))) { 12 | return error; 13 | } 14 | if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_MOST, 2))) { 15 | return error; 16 | } 17 | 18 | struct bar_config *bar = config->current_bar; 19 | 20 | char *end; 21 | int padding = strtol(argv[0], &end, 10); 22 | if (padding < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) { 23 | return cmd_results_new(CMD_INVALID, 24 | "[Bar %s] Invalid tray padding value: %s", bar->id, argv[0]); 25 | } 26 | 27 | if (argc == 2 && strcasecmp(argv[1], "px") != 0) { 28 | return cmd_results_new(CMD_INVALID, 29 | "Expected 'tray_padding [px]'"); 30 | } 31 | 32 | sway_log(SWAY_DEBUG, "[Bar %s] Setting tray padding to %d", bar->id, padding); 33 | config->current_bar->tray_padding = padding; 34 | return cmd_results_new(CMD_SUCCESS, NULL); 35 | #else 36 | return cmd_results_new(CMD_INVALID, 37 | "Sway has been compiled without tray support"); 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /sway/commands/bar/workspace_buttons.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | config->current_bar->workspace_buttons = 13 | parse_boolean(argv[0], config->current_bar->workspace_buttons); 14 | if (config->current_bar->workspace_buttons) { 15 | sway_log(SWAY_DEBUG, "Enabling workspace buttons on bar: %s", 16 | config->current_bar->id); 17 | } else { 18 | sway_log(SWAY_DEBUG, "Disabling workspace buttons on bar: %s", 19 | config->current_bar->id); 20 | } 21 | return cmd_results_new(CMD_SUCCESS, NULL); 22 | } 23 | -------------------------------------------------------------------------------- /sway/commands/bar/workspace_min_width.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "config.h" 4 | #include "sway/commands.h" 5 | #include "sway/config.h" 6 | #include "log.h" 7 | 8 | struct cmd_results *bar_cmd_workspace_min_width(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "workspace_min_width", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | 14 | struct bar_config *bar = config->current_bar; 15 | 16 | char *end; 17 | int min_width = strtol(argv[0], &end, 10); 18 | if (min_width < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) { 19 | return cmd_results_new(CMD_INVALID, 20 | "[Bar %s] Invalid minimum workspace button width value: %s", 21 | bar->id, argv[0]); 22 | } 23 | 24 | if (argc == 2 && strcasecmp(argv[1], "px") != 0) { 25 | return cmd_results_new(CMD_INVALID, 26 | "Expected 'workspace_min_width [px]'"); 27 | } 28 | 29 | sway_log(SWAY_DEBUG, "[Bar %s] Setting minimum workspace button width to %d", 30 | bar->id, min_width); 31 | config->current_bar->workspace_min_width = min_width; 32 | return cmd_results_new(CMD_SUCCESS, NULL); 33 | } 34 | -------------------------------------------------------------------------------- /sway/commands/bar/wrap_scroll.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "log.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | config->current_bar->wrap_scroll = 13 | parse_boolean(argv[0], config->current_bar->wrap_scroll); 14 | if (config->current_bar->wrap_scroll) { 15 | sway_log(SWAY_DEBUG, "Enabling wrap scroll on bar: %s", 16 | config->current_bar->id); 17 | } else { 18 | sway_log(SWAY_DEBUG, "Disabling wrap scroll on bar: %s", 19 | config->current_bar->id); 20 | } 21 | return cmd_results_new(CMD_SUCCESS, NULL); 22 | } 23 | -------------------------------------------------------------------------------- /sway/commands/create_output.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #if WLR_HAS_X11_BACKEND 6 | #include 7 | #endif 8 | #include "sway/commands.h" 9 | #include "sway/server.h" 10 | #include "log.h" 11 | 12 | static void create_output(struct wlr_backend *backend, void *data) { 13 | bool *done = data; 14 | if (*done) { 15 | return; 16 | } 17 | 18 | if (wlr_backend_is_wl(backend)) { 19 | wlr_wl_output_create(backend); 20 | *done = true; 21 | } else if (wlr_backend_is_headless(backend)) { 22 | wlr_headless_add_output(backend, 1920, 1080); 23 | *done = true; 24 | } 25 | #if WLR_HAS_X11_BACKEND 26 | else if (wlr_backend_is_x11(backend)) { 27 | wlr_x11_output_create(backend); 28 | *done = true; 29 | } 30 | #endif 31 | } 32 | 33 | /** 34 | * This command is intended for developer use only. 35 | */ 36 | struct cmd_results *cmd_create_output(int argc, char **argv) { 37 | sway_assert(wlr_backend_is_multi(server.backend), 38 | "Expected a multi backend"); 39 | 40 | bool done = false; 41 | wlr_multi_for_each_backend(server.backend, create_output, &done); 42 | 43 | if (!done) { 44 | return cmd_results_new(CMD_INVALID, 45 | "Can only create outputs for Wayland, X11 or headless backends"); 46 | } 47 | 48 | return cmd_results_new(CMD_SUCCESS, NULL); 49 | } 50 | -------------------------------------------------------------------------------- /sway/commands/default_border.c: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/tree/container.h" 5 | 6 | struct cmd_results *cmd_default_border(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "default_border", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | 12 | if (strcmp(argv[0], "none") == 0) { 13 | config->border = B_NONE; 14 | } else if (strcmp(argv[0], "normal") == 0) { 15 | config->border = B_NORMAL; 16 | } else if (strcmp(argv[0], "pixel") == 0) { 17 | config->border = B_PIXEL; 18 | } else { 19 | return cmd_results_new(CMD_INVALID, 20 | "Expected 'default_border ' or 'default_border '"); 21 | } 22 | if (argc == 2) { 23 | config->border_thickness = atoi(argv[1]); 24 | } 25 | 26 | return cmd_results_new(CMD_SUCCESS, NULL); 27 | } 28 | -------------------------------------------------------------------------------- /sway/commands/default_floating_border.c: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/tree/container.h" 5 | 6 | struct cmd_results *cmd_default_floating_border(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "default_floating_border", 9 | EXPECTED_AT_LEAST, 1))) { 10 | return error; 11 | } 12 | 13 | if (strcmp(argv[0], "none") == 0) { 14 | config->floating_border = B_NONE; 15 | } else if (strcmp(argv[0], "normal") == 0) { 16 | config->floating_border = B_NORMAL; 17 | } else if (strcmp(argv[0], "pixel") == 0) { 18 | config->floating_border = B_PIXEL; 19 | } else { 20 | return cmd_results_new(CMD_INVALID, 21 | "Expected 'default_floating_border ' " 22 | "or 'default_floating_border '"); 23 | } 24 | if (argc == 2) { 25 | config->floating_border_thickness = atoi(argv[1]); 26 | } 27 | 28 | return cmd_results_new(CMD_SUCCESS, NULL); 29 | } 30 | -------------------------------------------------------------------------------- /sway/commands/default_orientation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | 5 | struct cmd_results *cmd_default_orientation(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "default_orientation", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | if (strcasecmp(argv[0], "horizontal") == 0) { 11 | config->default_orientation = L_HORIZ; 12 | } else if (strcasecmp(argv[0], "vertical") == 0) { 13 | config->default_orientation = L_VERT; 14 | } else if (strcasecmp(argv[0], "auto") == 0) { 15 | // Do nothing 16 | } else { 17 | return cmd_results_new(CMD_INVALID, 18 | "Expected 'orientation '"); 19 | } 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/exec.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "log.h" 5 | #include "stringop.h" 6 | 7 | struct cmd_results *cmd_exec(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = cmd_exec_validate(argc, argv))) { 10 | return error; 11 | } 12 | if (config->reloading) { 13 | char *args = join_args(argv, argc); 14 | sway_log(SWAY_DEBUG, "Ignoring 'exec %s' due to reload", args); 15 | free(args); 16 | return cmd_results_new(CMD_SUCCESS, NULL); 17 | } 18 | return cmd_exec_process(argc, argv); 19 | } 20 | -------------------------------------------------------------------------------- /sway/commands/exit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/server.h" 5 | 6 | struct cmd_results *cmd_exit(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0))) { 9 | return error; 10 | } 11 | sway_terminate(0); 12 | return cmd_results_new(CMD_SUCCESS, NULL); 13 | } 14 | -------------------------------------------------------------------------------- /sway/commands/floating_minmax_size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "sway/commands.h" 8 | #include "log.h" 9 | 10 | static const char min_usage[] = 11 | "Expected 'floating_minimum_size x '"; 12 | 13 | static const char max_usage[] = 14 | "Expected 'floating_maximum_size x '"; 15 | 16 | static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name, 17 | const char *usage, int *config_width, int *config_height) { 18 | struct cmd_results *error; 19 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 3))) { 20 | return error; 21 | } 22 | 23 | char *err; 24 | int width = (int)strtol(argv[0], &err, 10); 25 | if (*err) { 26 | return cmd_results_new(CMD_INVALID, "%s", usage); 27 | } 28 | 29 | if (strcmp(argv[1], "x") != 0) { 30 | return cmd_results_new(CMD_INVALID, "%s", usage); 31 | } 32 | 33 | int height = (int)strtol(argv[2], &err, 10); 34 | if (*err) { 35 | return cmd_results_new(CMD_INVALID, "%s", usage); 36 | } 37 | 38 | *config_width = width; 39 | *config_height = height; 40 | 41 | return cmd_results_new(CMD_SUCCESS, NULL); 42 | } 43 | 44 | struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) { 45 | return handle_command(argc, argv, "floating_minimum_size", min_usage, 46 | &config->floating_minimum_width, &config->floating_minimum_height); 47 | } 48 | 49 | struct cmd_results *cmd_floating_maximum_size(int argc, char **argv) { 50 | return handle_command(argc, argv, "floating_maximum_size", max_usage, 51 | &config->floating_maximum_width, &config->floating_maximum_height); 52 | } 53 | -------------------------------------------------------------------------------- /sway/commands/floating_modifier.c: -------------------------------------------------------------------------------- 1 | #include "strings.h" 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/input/keyboard.h" 5 | 6 | struct cmd_results *cmd_floating_modifier(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | 12 | if (strcasecmp(argv[0], "none") == 0) { 13 | config->floating_mod = 0; 14 | return cmd_results_new(CMD_SUCCESS, NULL); 15 | } 16 | 17 | uint32_t mod = get_modifier_mask_by_name(argv[0]); 18 | if (!mod) { 19 | return cmd_results_new(CMD_INVALID, "Invalid modifier"); 20 | } 21 | 22 | if (argc == 1 || strcasecmp(argv[1], "normal") == 0) { 23 | config->floating_mod_inverse = false; 24 | } else if (strcasecmp(argv[1], "inverse") == 0) { 25 | config->floating_mod_inverse = true; 26 | } else { 27 | return cmd_results_new(CMD_INVALID, 28 | "Usage: floating_modifier [inverse|normal]"); 29 | } 30 | 31 | config->floating_mod = mod; 32 | 33 | return cmd_results_new(CMD_SUCCESS, NULL); 34 | } 35 | -------------------------------------------------------------------------------- /sway/commands/focus_follows_mouse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "util.h" 5 | 6 | struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } else if(strcmp(argv[0], "no") == 0) { 11 | config->focus_follows_mouse = FOLLOWS_NO; 12 | } else if(strcmp(argv[0], "yes") == 0) { 13 | config->focus_follows_mouse = FOLLOWS_YES; 14 | } else if(strcmp(argv[0], "always") == 0) { 15 | config->focus_follows_mouse = FOLLOWS_ALWAYS; 16 | } else { 17 | return cmd_results_new(CMD_FAILURE, 18 | "Expected 'focus_follows_mouse no|yes|always'"); 19 | } 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/focus_on_window_activation.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | 3 | struct cmd_results *cmd_focus_on_window_activation(int argc, char **argv) { 4 | struct cmd_results *error = NULL; 5 | if ((error = checkarg(argc, "focus_on_window_activation", 6 | EXPECTED_EQUAL_TO, 1))) { 7 | return error; 8 | } 9 | 10 | if (strcmp(argv[0], "smart") == 0) { 11 | config->focus_on_window_activation = FOWA_SMART; 12 | } else if (strcmp(argv[0], "urgent") == 0) { 13 | config->focus_on_window_activation = FOWA_URGENT; 14 | } else if (strcmp(argv[0], "focus") == 0) { 15 | config->focus_on_window_activation = FOWA_FOCUS; 16 | } else if (strcmp(argv[0], "none") == 0) { 17 | config->focus_on_window_activation = FOWA_NONE; 18 | } else { 19 | return cmd_results_new(CMD_INVALID, 20 | "Expected " 21 | "'focus_on_window_activation smart|urgent|focus|none'"); 22 | } 23 | 24 | return cmd_results_new(CMD_SUCCESS, NULL); 25 | } 26 | -------------------------------------------------------------------------------- /sway/commands/focus_wrapping.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "util.h" 5 | 6 | struct cmd_results *cmd_focus_wrapping(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "focus_wrapping", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | 12 | if (strcasecmp(argv[0], "force") == 0) { 13 | config->focus_wrapping = WRAP_FORCE; 14 | } else if (strcasecmp(argv[0], "workspace") == 0) { 15 | config->focus_wrapping = WRAP_WORKSPACE; 16 | } else if (parse_boolean(argv[0], config->focus_wrapping == WRAP_YES)) { 17 | config->focus_wrapping = WRAP_YES; 18 | } else { 19 | config->focus_wrapping = WRAP_NO; 20 | } 21 | 22 | return cmd_results_new(CMD_SUCCESS, NULL); 23 | } 24 | -------------------------------------------------------------------------------- /sway/commands/font.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "log.h" 5 | #include "stringop.h" 6 | #include 7 | 8 | struct cmd_results *cmd_font(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | char *font = join_args(argv, argc); 14 | free(config->font); 15 | 16 | if (has_prefix(font, "pango:")) { 17 | config->pango_markup = true; 18 | config->font = strdup(font + strlen("pango:")); 19 | free(font); 20 | } else { 21 | config->pango_markup = false; 22 | config->font = font; 23 | } 24 | 25 | // Parse the font early so we can reject it if it's not valid for pango. 26 | // Also avoids re-parsing each time we render text. 27 | PangoFontDescription *font_description = pango_font_description_from_string(config->font); 28 | 29 | const char *family = pango_font_description_get_family(font_description); 30 | if (family == NULL) { 31 | pango_font_description_free(font_description); 32 | return cmd_results_new(CMD_FAILURE, "Invalid font family."); 33 | } 34 | 35 | const gint size = pango_font_description_get_size(font_description); 36 | if (size == 0) { 37 | pango_font_description_free(font_description); 38 | return cmd_results_new(CMD_FAILURE, "Invalid font size."); 39 | } 40 | 41 | if (config->font_description != NULL) { 42 | pango_font_description_free(config->font_description); 43 | } 44 | 45 | config->font_description = font_description; 46 | config_update_font_height(); 47 | 48 | return cmd_results_new(CMD_SUCCESS, NULL); 49 | } 50 | -------------------------------------------------------------------------------- /sway/commands/for_window.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/criteria.h" 4 | #include "list.h" 5 | #include "log.h" 6 | #include "stringop.h" 7 | 8 | struct cmd_results *cmd_for_window(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) { 11 | return error; 12 | } 13 | 14 | char *err_str = NULL; 15 | struct criteria *criteria = criteria_parse(argv[0], &err_str); 16 | if (!criteria) { 17 | error = cmd_results_new(CMD_INVALID, "%s", err_str); 18 | free(err_str); 19 | return error; 20 | } 21 | 22 | criteria->type = CT_COMMAND; 23 | criteria->cmdlist = join_args(argv + 1, argc - 1); 24 | 25 | // Check if it already exists 26 | if (criteria_already_exists(criteria)) { 27 | sway_log(SWAY_DEBUG, "for_window already exists: '%s' -> '%s'", 28 | criteria->raw, criteria->cmdlist); 29 | criteria_destroy(criteria); 30 | return cmd_results_new(CMD_SUCCESS, NULL); 31 | } 32 | 33 | list_add(config->criteria, criteria); 34 | sway_log(SWAY_DEBUG, "for_window: '%s' -> '%s' added", criteria->raw, criteria->cmdlist); 35 | 36 | return cmd_results_new(CMD_SUCCESS, NULL); 37 | } 38 | -------------------------------------------------------------------------------- /sway/commands/force_display_urgency_hint.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | #include 4 | 5 | struct cmd_results *cmd_force_display_urgency_hint(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "force_display_urgency_hint", 8 | EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | 12 | errno = 0; 13 | char *end; 14 | int timeout = (int)strtol(argv[0], &end, 10); 15 | if (errno || end == argv[0] || (*end && strcmp(end, "ms") != 0)) { 16 | return cmd_results_new(CMD_INVALID, "timeout integer invalid"); 17 | } 18 | 19 | if (argc > 1 && strcmp(argv[1], "ms") != 0) { 20 | return cmd_results_new(CMD_INVALID, 21 | "Expected 'force_display_urgency_hint [ms]'"); 22 | } 23 | 24 | config->urgent_timeout = timeout > 0 ? timeout : 0; 25 | 26 | return cmd_results_new(CMD_SUCCESS, NULL); 27 | } 28 | -------------------------------------------------------------------------------- /sway/commands/force_focus_wrapping.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | #include "log.h" 4 | #include "util.h" 5 | 6 | struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) { 7 | sway_log(SWAY_INFO, "Warning: force_focus_wrapping is deprecated. " 8 | "Use focus_wrapping instead."); 9 | if (config->reading) { 10 | config_add_swaynag_warning("force_focus_wrapping is deprecated. " 11 | "Use focus_wrapping instead."); 12 | } 13 | 14 | struct cmd_results *error = 15 | checkarg(argc, "force_focus_wrapping", EXPECTED_EQUAL_TO, 1); 16 | if (error) { 17 | return error; 18 | } 19 | 20 | if (parse_boolean(argv[0], config->focus_wrapping == WRAP_FORCE)) { 21 | config->focus_wrapping = WRAP_FORCE; 22 | } else { 23 | config->focus_wrapping = WRAP_YES; 24 | } 25 | 26 | return cmd_results_new(CMD_SUCCESS, NULL); 27 | } 28 | -------------------------------------------------------------------------------- /sway/commands/fullscreen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "log.h" 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "sway/tree/arrange.h" 6 | #include "sway/tree/container.h" 7 | #include "sway/tree/view.h" 8 | #include "sway/tree/workspace.h" 9 | #include "util.h" 10 | 11 | // fullscreen [enable|disable|toggle] [global] 12 | struct cmd_results *cmd_fullscreen(int argc, char **argv) { 13 | struct cmd_results *error = NULL; 14 | if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_MOST, 2))) { 15 | return error; 16 | } 17 | if (!root->outputs->length) { 18 | return cmd_results_new(CMD_FAILURE, 19 | "Can't run this command while there's no outputs connected."); 20 | } 21 | struct sway_container *container = config->handler_context.container; 22 | 23 | if (!container) { 24 | // If the focus is not a container, do nothing successfully 25 | return cmd_results_new(CMD_SUCCESS, NULL); 26 | } else if (!container->pending.workspace) { 27 | // If in the scratchpad, operate on the highest container 28 | while (container->pending.parent) { 29 | container = container->pending.parent; 30 | } 31 | } 32 | 33 | bool is_fullscreen = container->pending.fullscreen_mode != FULLSCREEN_NONE; 34 | bool global = false; 35 | bool enable = !is_fullscreen; 36 | 37 | if (argc >= 1) { 38 | if (strcasecmp(argv[0], "global") == 0) { 39 | global = true; 40 | } else { 41 | enable = parse_boolean(argv[0], is_fullscreen); 42 | } 43 | } 44 | 45 | if (argc >= 2) { 46 | global = strcasecmp(argv[1], "global") == 0; 47 | } 48 | 49 | enum sway_fullscreen_mode mode = FULLSCREEN_NONE; 50 | if (enable) { 51 | mode = global ? FULLSCREEN_GLOBAL : FULLSCREEN_WORKSPACE; 52 | } 53 | 54 | container_set_fullscreen(container, mode); 55 | arrange_root(); 56 | 57 | return cmd_results_new(CMD_SUCCESS, NULL); 58 | } 59 | -------------------------------------------------------------------------------- /sway/commands/hide_edge_borders.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | #include "sway/tree/arrange.h" 4 | #include "sway/tree/view.h" 5 | 6 | struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { 7 | const char *expected_syntax = "Expected 'hide_edge_borders [--i3] " 8 | "none|vertical|horizontal|both|smart|smart_no_gaps"; 9 | 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_AT_LEAST, 1))) { 12 | return error; 13 | } 14 | 15 | bool hide_lone_tab = false; 16 | if (strcmp(*argv, "--i3") == 0) { 17 | hide_lone_tab = true; 18 | ++argv; 19 | --argc; 20 | } 21 | 22 | if (!argc) { 23 | return cmd_results_new(CMD_INVALID, "%s", expected_syntax); 24 | } 25 | 26 | if (strcmp(argv[0], "none") == 0) { 27 | config->hide_edge_borders = E_NONE; 28 | } else if (strcmp(argv[0], "vertical") == 0) { 29 | config->hide_edge_borders = E_VERTICAL; 30 | } else if (strcmp(argv[0], "horizontal") == 0) { 31 | config->hide_edge_borders = E_HORIZONTAL; 32 | } else if (strcmp(argv[0], "both") == 0) { 33 | config->hide_edge_borders = E_BOTH; 34 | } else if (strcmp(argv[0], "smart") == 0) { 35 | config->hide_edge_borders = E_NONE; 36 | config->hide_edge_borders_smart = ESMART_ON; 37 | } else if (strcmp(argv[0], "smart_no_gaps") == 0) { 38 | config->hide_edge_borders = E_NONE; 39 | config->hide_edge_borders_smart = ESMART_NO_GAPS; 40 | } else { 41 | return cmd_results_new(CMD_INVALID, "%s", expected_syntax); 42 | } 43 | config->hide_lone_tab = hide_lone_tab; 44 | 45 | arrange_root(); 46 | 47 | return cmd_results_new(CMD_SUCCESS, NULL); 48 | } 49 | -------------------------------------------------------------------------------- /sway/commands/include.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | 4 | struct cmd_results *cmd_include(int argc, char **argv) { 5 | struct cmd_results *error = NULL; 6 | if ((error = checkarg(argc, "include", EXPECTED_AT_LEAST, 1))) { 7 | return error; 8 | } 9 | char *files = join_args(argv, argc); 10 | // We don't care if the included config(s) fails to load. 11 | load_include_configs(files, config, &config->swaynag_config_errors); 12 | 13 | return cmd_results_new(CMD_SUCCESS, NULL); 14 | } 15 | -------------------------------------------------------------------------------- /sway/commands/inhibit_idle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/desktop/idle_inhibit_v1.h" 5 | #include "sway/tree/container.h" 6 | #include "sway/tree/view.h" 7 | 8 | struct cmd_results *cmd_inhibit_idle(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "inhibit_idle", EXPECTED_EQUAL_TO, 1))) { 11 | return error; 12 | } 13 | 14 | struct sway_container *con = config->handler_context.container; 15 | if (!con || !con->view) { 16 | return cmd_results_new(CMD_INVALID, 17 | "Only views can have idle inhibitors"); 18 | } 19 | 20 | bool clear = false; 21 | enum sway_idle_inhibit_mode mode; 22 | if (strcmp(argv[0], "focus") == 0) { 23 | mode = INHIBIT_IDLE_FOCUS; 24 | } else if (strcmp(argv[0], "fullscreen") == 0) { 25 | mode = INHIBIT_IDLE_FULLSCREEN; 26 | } else if (strcmp(argv[0], "open") == 0) { 27 | mode = INHIBIT_IDLE_OPEN; 28 | } else if (strcmp(argv[0], "none") == 0) { 29 | clear = true; 30 | } else if (strcmp(argv[0], "visible") == 0) { 31 | mode = INHIBIT_IDLE_VISIBLE; 32 | } else { 33 | return cmd_results_new(CMD_INVALID, 34 | "Expected `inhibit_idle focus|fullscreen|open|none|visible`"); 35 | } 36 | 37 | struct sway_idle_inhibitor_v1 *inhibitor = 38 | sway_idle_inhibit_v1_user_inhibitor_for_view(con->view); 39 | if (inhibitor) { 40 | if (clear) { 41 | sway_idle_inhibit_v1_user_inhibitor_destroy(inhibitor); 42 | } else { 43 | inhibitor->mode = mode; 44 | sway_idle_inhibit_v1_check_active(); 45 | } 46 | } else if (!clear) { 47 | sway_idle_inhibit_v1_user_inhibitor_register(con->view, mode); 48 | } 49 | 50 | return cmd_results_new(CMD_SUCCESS, NULL); 51 | } 52 | -------------------------------------------------------------------------------- /sway/commands/input/accel_profile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | 7 | struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) { 10 | return error; 11 | } 12 | struct input_config *ic = config->handler_context.input_config; 13 | if (!ic) { 14 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 15 | } 16 | 17 | if (strcasecmp(argv[0], "adaptive") == 0) { 18 | ic->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; 19 | } else if (strcasecmp(argv[0], "flat") == 0) { 20 | ic->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; 21 | } else { 22 | return cmd_results_new(CMD_INVALID, 23 | "Expected 'accel_profile '"); 24 | } 25 | 26 | return cmd_results_new(CMD_SUCCESS, NULL); 27 | } 28 | -------------------------------------------------------------------------------- /sway/commands/input/calibration_matrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "log.h" 7 | #include "stringop.h" 8 | #include "util.h" 9 | 10 | struct cmd_results *input_cmd_calibration_matrix(int argc, char **argv) { 11 | struct cmd_results *error = NULL; 12 | if ((error = checkarg(argc, "calibration_matrix", EXPECTED_EQUAL_TO, 6))) { 13 | return error; 14 | } 15 | struct input_config *ic = config->handler_context.input_config; 16 | if (!ic) { 17 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 18 | } 19 | 20 | float parsed[6]; 21 | for (int i = 0; i < argc; ++i) { 22 | char *item = argv[i]; 23 | float x = parse_float(item); 24 | if (isnan(x)) { 25 | return cmd_results_new(CMD_FAILURE, "calibration_matrix: unable to parse float: %s", item); 26 | } 27 | parsed[i] = x; 28 | } 29 | 30 | ic->calibration_matrix.configured = true; 31 | memcpy(ic->calibration_matrix.matrix, parsed, sizeof(ic->calibration_matrix.matrix)); 32 | 33 | return cmd_results_new(CMD_SUCCESS, NULL); 34 | } 35 | -------------------------------------------------------------------------------- /sway/commands/input/click_method.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "sway/input/input-manager.h" 6 | #include "log.h" 7 | 8 | struct cmd_results *input_cmd_click_method(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | if (strcasecmp(argv[0], "none") == 0) { 19 | ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; 20 | } else if (strcasecmp(argv[0], "button_areas") == 0) { 21 | ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; 22 | } else if (strcasecmp(argv[0], "clickfinger") == 0) { 23 | ic->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; 24 | } else { 25 | return cmd_results_new(CMD_INVALID, 26 | "Expected 'click_method '"); 27 | } 28 | 29 | return cmd_results_new(CMD_SUCCESS, NULL); 30 | } 31 | -------------------------------------------------------------------------------- /sway/commands/input/clickfinger_button_map.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | 7 | struct cmd_results *input_cmd_clickfinger_button_map(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "clickfinger_button_map", EXPECTED_AT_LEAST, 1))) { 10 | return error; 11 | } 12 | struct input_config *ic = config->handler_context.input_config; 13 | if (!ic) { 14 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 15 | } 16 | 17 | if (strcasecmp(argv[0], "lrm") == 0) { 18 | ic->clickfinger_button_map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM; 19 | } else if (strcasecmp(argv[0], "lmr") == 0) { 20 | ic->clickfinger_button_map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LMR; 21 | } else { 22 | return cmd_results_new(CMD_INVALID, 23 | "Expected 'clickfinger_button_map '"); 24 | } 25 | 26 | return cmd_results_new(CMD_SUCCESS, NULL); 27 | } 28 | -------------------------------------------------------------------------------- /sway/commands/input/drag.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "util.h" 7 | 8 | struct cmd_results *input_cmd_drag(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "drag", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | if (parse_boolean(argv[0], true)) { 19 | ic->drag = LIBINPUT_CONFIG_DRAG_ENABLED; 20 | } else { 21 | ic->drag = LIBINPUT_CONFIG_DRAG_DISABLED; 22 | } 23 | 24 | return cmd_results_new(CMD_SUCCESS, NULL); 25 | } 26 | -------------------------------------------------------------------------------- /sway/commands/input/drag_lock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "util.h" 7 | 8 | struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | #if HAVE_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY 19 | if (strcmp(argv[0], "enabled_sticky") == 0) { 20 | ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY; 21 | } else 22 | #endif 23 | if (parse_boolean(argv[0], true)) { 24 | ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; 25 | } else { 26 | ic->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; 27 | } 28 | 29 | return cmd_results_new(CMD_SUCCESS, NULL); 30 | } 31 | -------------------------------------------------------------------------------- /sway/commands/input/dwt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "util.h" 7 | 8 | struct cmd_results *input_cmd_dwt(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | if (parse_boolean(argv[0], true)) { 19 | ic->dwt = LIBINPUT_CONFIG_DWT_ENABLED; 20 | } else { 21 | ic->dwt = LIBINPUT_CONFIG_DWT_DISABLED; 22 | } 23 | 24 | return cmd_results_new(CMD_SUCCESS, NULL); 25 | } 26 | -------------------------------------------------------------------------------- /sway/commands/input/dwtp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "util.h" 7 | 8 | struct cmd_results *input_cmd_dwtp(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "dwtp", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | if (parse_boolean(argv[0], true)) { 19 | ic->dwtp = LIBINPUT_CONFIG_DWTP_ENABLED; 20 | } else { 21 | ic->dwtp = LIBINPUT_CONFIG_DWTP_DISABLED; 22 | } 23 | 24 | return cmd_results_new(CMD_SUCCESS, NULL); 25 | } 26 | -------------------------------------------------------------------------------- /sway/commands/input/left_handed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "util.h" 7 | 8 | struct cmd_results *input_cmd_left_handed(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "left_handed", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | ic->left_handed = parse_boolean(argv[0], true); 19 | 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/input/map_to_output.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "log.h" 7 | 8 | struct cmd_results *input_cmd_map_to_output(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "map_to_output", EXPECTED_EQUAL_TO, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | ic->mapped_to = MAPPED_TO_OUTPUT; 19 | ic->mapped_to_output = strdup(argv[0]); 20 | 21 | return cmd_results_new(CMD_SUCCESS, NULL); 22 | } 23 | -------------------------------------------------------------------------------- /sway/commands/input/map_to_region.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | 6 | struct cmd_results *input_cmd_map_to_region(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "map_to_region", EXPECTED_EQUAL_TO, 4))) { 9 | return error; 10 | } 11 | struct input_config *ic = config->handler_context.input_config; 12 | if (!ic) { 13 | return cmd_results_new(CMD_FAILURE, "No input device defined"); 14 | } 15 | 16 | ic->mapped_to = MAPPED_TO_REGION; 17 | ic->mapped_to_region = calloc(1, sizeof(struct wlr_box)); 18 | 19 | const char *errstr; 20 | char *end; 21 | 22 | ic->mapped_to_region->x = strtol(argv[0], &end, 10); 23 | if (end[0] != '\0') { 24 | errstr = "Invalid X coordinate"; 25 | goto error; 26 | } 27 | 28 | ic->mapped_to_region->y = strtol(argv[1], &end, 10); 29 | if (end[0] != '\0') { 30 | errstr = "Invalid Y coordinate"; 31 | goto error; 32 | } 33 | 34 | ic->mapped_to_region->width = strtol(argv[2], &end, 10); 35 | if (end[0] != '\0' || ic->mapped_to_region->width < 1) { 36 | errstr = "Invalid width"; 37 | goto error; 38 | } 39 | 40 | ic->mapped_to_region->height = strtol(argv[3], &end, 10); 41 | if (end[0] != '\0' || ic->mapped_to_region->height < 1) { 42 | errstr = "Invalid height"; 43 | goto error; 44 | } 45 | 46 | return cmd_results_new(CMD_SUCCESS, NULL); 47 | 48 | error: 49 | free(ic->mapped_to_region); 50 | ic->mapped_to_region = NULL; 51 | return cmd_results_new(CMD_FAILURE, "%s", errstr); 52 | } 53 | -------------------------------------------------------------------------------- /sway/commands/input/middle_emulation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "util.h" 7 | 8 | struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | if (parse_boolean(argv[0], true)) { 19 | ic->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; 20 | } else { 21 | ic->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; 22 | } 23 | 24 | return cmd_results_new(CMD_SUCCESS, NULL); 25 | } 26 | -------------------------------------------------------------------------------- /sway/commands/input/natural_scroll.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "util.h" 7 | 8 | struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | ic->natural_scroll = parse_boolean(argv[0], true); 19 | 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/input/pointer_accel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "sway/config.h" 5 | #include "sway/commands.h" 6 | #include "sway/input/input-manager.h" 7 | #include "util.h" 8 | 9 | struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) { 12 | return error; 13 | } 14 | struct input_config *ic = config->handler_context.input_config; 15 | if (!ic) { 16 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 17 | } 18 | 19 | float pointer_accel = parse_float(argv[0]); 20 | if (isnan(pointer_accel)) { 21 | return cmd_results_new(CMD_INVALID, 22 | "Invalid pointer accel; expected float."); 23 | } if (pointer_accel < -1 || pointer_accel > 1) { 24 | return cmd_results_new(CMD_INVALID, "Input out of range [-1, 1]"); 25 | } 26 | ic->pointer_accel = pointer_accel; 27 | 28 | return cmd_results_new(CMD_SUCCESS, NULL); 29 | } 30 | -------------------------------------------------------------------------------- /sway/commands/input/repeat_delay.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | 7 | struct cmd_results *input_cmd_repeat_delay(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "repeat_delay", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | struct input_config *ic = config->handler_context.input_config; 13 | if (!ic) { 14 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 15 | } 16 | 17 | int repeat_delay = atoi(argv[0]); 18 | if (repeat_delay < 0) { 19 | return cmd_results_new(CMD_INVALID, "Repeat delay cannot be negative"); 20 | } 21 | ic->repeat_delay = repeat_delay; 22 | 23 | return cmd_results_new(CMD_SUCCESS, NULL); 24 | } 25 | -------------------------------------------------------------------------------- /sway/commands/input/repeat_rate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | 7 | struct cmd_results *input_cmd_repeat_rate(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "repeat_rate", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | struct input_config *ic = config->handler_context.input_config; 13 | if (!ic) { 14 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 15 | } 16 | 17 | int repeat_rate = atoi(argv[0]); 18 | if (repeat_rate < 0) { 19 | return cmd_results_new(CMD_INVALID, "Repeat rate cannot be negative"); 20 | } 21 | ic->repeat_rate = repeat_rate; 22 | 23 | return cmd_results_new(CMD_SUCCESS, NULL); 24 | } 25 | -------------------------------------------------------------------------------- /sway/commands/input/rotation_angle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "sway/config.h" 5 | #include "sway/commands.h" 6 | #include "sway/input/input-manager.h" 7 | #include "util.h" 8 | 9 | struct cmd_results *input_cmd_rotation_angle(int argc, char **argv) { 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "rotation_angle", EXPECTED_AT_LEAST, 1))) { 12 | return error; 13 | } 14 | struct input_config *ic = config->handler_context.input_config; 15 | if (!ic) { 16 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 17 | } 18 | 19 | float rotation_angle = parse_float(argv[0]); 20 | if (isnan(rotation_angle)) { 21 | return cmd_results_new(CMD_INVALID, 22 | "Invalid rotation_angle; expected float."); 23 | } if (rotation_angle < 0 || rotation_angle > 360) { 24 | return cmd_results_new(CMD_INVALID, "Input out of range [0, 360)"); 25 | } 26 | ic->rotation_angle = rotation_angle; 27 | 28 | return cmd_results_new(CMD_SUCCESS, NULL); 29 | } 30 | -------------------------------------------------------------------------------- /sway/commands/input/scroll_button.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/config.h" 3 | #include "sway/commands.h" 4 | #include "sway/input/cursor.h" 5 | 6 | struct cmd_results *input_cmd_scroll_button(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "scroll_button", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | struct input_config *ic = config->handler_context.input_config; 12 | if (!ic) { 13 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 14 | } 15 | 16 | if (strcmp(*argv, "disable") == 0) { 17 | ic->scroll_button = 0; 18 | return cmd_results_new(CMD_SUCCESS, NULL); 19 | } 20 | 21 | char *message = NULL; 22 | uint32_t button = get_mouse_button(*argv, &message); 23 | if (message) { 24 | error = cmd_results_new(CMD_INVALID, "%s", message); 25 | free(message); 26 | return error; 27 | } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN 28 | || button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) { 29 | return cmd_results_new(CMD_INVALID, 30 | "X11 axis buttons are not supported for scroll_button"); 31 | } else if (!button) { 32 | return cmd_results_new(CMD_INVALID, "Unknown button %s", *argv); 33 | } 34 | ic->scroll_button = button; 35 | 36 | return cmd_results_new(CMD_SUCCESS, NULL); 37 | } 38 | -------------------------------------------------------------------------------- /sway/commands/input/scroll_button_lock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "sway/config.h" 5 | #include "sway/commands.h" 6 | #include "sway/input/input-manager.h" 7 | #include "util.h" 8 | 9 | struct cmd_results *input_cmd_scroll_button_lock(int argc, char **argv) { 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "scroll_button_lock", EXPECTED_AT_LEAST, 1))) { 12 | return error; 13 | } 14 | struct input_config *ic = config->handler_context.input_config; 15 | if (!ic) { 16 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 17 | } 18 | 19 | if (parse_boolean(argv[0], true)) { 20 | ic->scroll_button_lock = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED; 21 | } else { 22 | ic->scroll_button_lock = LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED; 23 | } 24 | 25 | return cmd_results_new(CMD_SUCCESS, NULL); 26 | } 27 | -------------------------------------------------------------------------------- /sway/commands/input/scroll_factor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "sway/config.h" 6 | #include "sway/commands.h" 7 | #include "sway/input/input-manager.h" 8 | #include "util.h" 9 | 10 | struct cmd_results *input_cmd_scroll_factor(int argc, char **argv) { 11 | struct cmd_results *error = NULL; 12 | if ((error = checkarg(argc, "scroll_factor", EXPECTED_AT_LEAST, 1))) { 13 | return error; 14 | } 15 | struct input_config *ic = config->handler_context.input_config; 16 | if (!ic) { 17 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 18 | } 19 | 20 | float scroll_factor = parse_float(argv[0]); 21 | if (isnan(scroll_factor)) { 22 | return cmd_results_new(CMD_INVALID, 23 | "Invalid scroll factor; expected float."); 24 | } else if (scroll_factor < 0) { 25 | return cmd_results_new(CMD_INVALID, 26 | "Scroll factor cannot be negative."); 27 | } 28 | ic->scroll_factor = scroll_factor; 29 | 30 | return cmd_results_new(CMD_SUCCESS, NULL); 31 | } 32 | -------------------------------------------------------------------------------- /sway/commands/input/scroll_method.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | 7 | struct cmd_results *input_cmd_scroll_method(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) { 10 | return error; 11 | } 12 | struct input_config *ic = config->handler_context.input_config; 13 | if (!ic) { 14 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 15 | } 16 | 17 | if (strcasecmp(argv[0], "none") == 0) { 18 | ic->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; 19 | } else if (strcasecmp(argv[0], "two_finger") == 0) { 20 | ic->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; 21 | } else if (strcasecmp(argv[0], "edge") == 0) { 22 | ic->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; 23 | } else if (strcasecmp(argv[0], "on_button_down") == 0) { 24 | ic->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; 25 | } else { 26 | return cmd_results_new(CMD_INVALID, 27 | "Expected 'scroll_method '"); 28 | } 29 | 30 | return cmd_results_new(CMD_SUCCESS, NULL); 31 | } 32 | -------------------------------------------------------------------------------- /sway/commands/input/tap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "log.h" 7 | #include "util.h" 8 | 9 | struct cmd_results *input_cmd_tap(int argc, char **argv) { 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) { 12 | return error; 13 | } 14 | struct input_config *ic = config->handler_context.input_config; 15 | if (!ic) { 16 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 17 | } 18 | 19 | if (parse_boolean(argv[0], true)) { 20 | ic->tap = LIBINPUT_CONFIG_TAP_ENABLED; 21 | } else { 22 | ic->tap = LIBINPUT_CONFIG_TAP_DISABLED; 23 | } 24 | 25 | return cmd_results_new(CMD_SUCCESS, NULL); 26 | } 27 | -------------------------------------------------------------------------------- /sway/commands/input/tap_button_map.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | 7 | struct cmd_results *input_cmd_tap_button_map(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "tap_button_map", EXPECTED_AT_LEAST, 1))) { 10 | return error; 11 | } 12 | struct input_config *ic = config->handler_context.input_config; 13 | if (!ic) { 14 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 15 | } 16 | 17 | if (strcasecmp(argv[0], "lrm") == 0) { 18 | ic->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LRM; 19 | } else if (strcasecmp(argv[0], "lmr") == 0) { 20 | ic->tap_button_map = LIBINPUT_CONFIG_TAP_MAP_LMR; 21 | } else { 22 | return cmd_results_new(CMD_INVALID, 23 | "Expected 'tap_button_map '"); 24 | } 25 | 26 | return cmd_results_new(CMD_SUCCESS, NULL); 27 | } 28 | -------------------------------------------------------------------------------- /sway/commands/input/xkb_capslock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "sway/input/input-manager.h" 6 | #include "util.h" 7 | 8 | struct cmd_results *input_cmd_xkb_capslock(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "xkb_capslock", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | ic->xkb_capslock = parse_boolean(argv[0], false); 19 | 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/input/xkb_file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "log.h" 6 | #include "stringop.h" 7 | 8 | struct cmd_results *input_cmd_xkb_file(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "xkb_file", EXPECTED_EQUAL_TO, 1))) { 11 | return error; 12 | } 13 | struct input_config *ic = config->handler_context.input_config; 14 | if (!ic) { 15 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 | } 17 | 18 | if (strcmp(argv[0], "-") == 0) { 19 | free(ic->xkb_file); 20 | ic->xkb_file = NULL; 21 | } else { 22 | ic->xkb_file = strdup(argv[0]); 23 | if (!expand_path(&ic->xkb_file)) { 24 | error = cmd_results_new(CMD_INVALID, "Invalid syntax (%s)", 25 | ic->xkb_file); 26 | free(ic->xkb_file); 27 | ic->xkb_file = NULL; 28 | return error; 29 | } 30 | if (!ic->xkb_file) { 31 | sway_log(SWAY_ERROR, "Failed to allocate expanded path"); 32 | return cmd_results_new(CMD_FAILURE, "Unable to allocate resource"); 33 | } 34 | 35 | bool can_access = access(ic->xkb_file, F_OK) != -1; 36 | if (!can_access) { 37 | sway_log_errno(SWAY_ERROR, "Unable to access xkb file '%s'", 38 | ic->xkb_file); 39 | config_add_swaynag_warning("Unable to access xkb file '%s'", 40 | ic->xkb_file); 41 | } 42 | } 43 | ic->xkb_file_is_set = true; 44 | 45 | sway_log(SWAY_DEBUG, "set-xkb_file for config: %s file: %s", 46 | ic->identifier, ic->xkb_file); 47 | return cmd_results_new(CMD_SUCCESS, NULL); 48 | } 49 | -------------------------------------------------------------------------------- /sway/commands/input/xkb_layout.c: -------------------------------------------------------------------------------- 1 | #include "sway/config.h" 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | 5 | struct cmd_results *input_cmd_xkb_layout(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "xkb_layout", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | struct input_config *ic = config->handler_context.input_config; 11 | if (!ic) { 12 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 13 | } 14 | 15 | ic->xkb_layout = strdup(argv[0]); 16 | 17 | sway_log(SWAY_DEBUG, "set-xkb_layout for config: %s layout: %s", 18 | ic->identifier, ic->xkb_layout); 19 | return cmd_results_new(CMD_SUCCESS, NULL); 20 | } 21 | -------------------------------------------------------------------------------- /sway/commands/input/xkb_model.c: -------------------------------------------------------------------------------- 1 | #include "sway/config.h" 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | 5 | struct cmd_results *input_cmd_xkb_model(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "xkb_model", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | struct input_config *ic = config->handler_context.input_config; 11 | if (!ic) { 12 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 13 | } 14 | 15 | ic->xkb_model = strdup(argv[0]); 16 | 17 | sway_log(SWAY_DEBUG, "set-xkb_model for config: %s model: %s", 18 | ic->identifier, ic->xkb_model); 19 | return cmd_results_new(CMD_SUCCESS, NULL); 20 | } 21 | -------------------------------------------------------------------------------- /sway/commands/input/xkb_numlock.c: -------------------------------------------------------------------------------- 1 | #include "sway/config.h" 2 | #include "sway/commands.h" 3 | #include "util.h" 4 | 5 | struct cmd_results *input_cmd_xkb_numlock(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "xkb_numlock", EXPECTED_AT_LEAST, 1))) { 8 | return error; 9 | } 10 | struct input_config *ic = config->handler_context.input_config; 11 | if (!ic) { 12 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 13 | } 14 | 15 | ic->xkb_numlock = parse_boolean(argv[0], false); 16 | 17 | return cmd_results_new(CMD_SUCCESS, NULL); 18 | } 19 | -------------------------------------------------------------------------------- /sway/commands/input/xkb_options.c: -------------------------------------------------------------------------------- 1 | #include "sway/config.h" 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | 5 | struct cmd_results *input_cmd_xkb_options(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "xkb_options", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | struct input_config *ic = config->handler_context.input_config; 11 | if (!ic) { 12 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 13 | } 14 | 15 | ic->xkb_options = strdup(argv[0]); 16 | 17 | sway_log(SWAY_DEBUG, "set-xkb_options for config: %s options: %s", 18 | ic->identifier, ic->xkb_options); 19 | return cmd_results_new(CMD_SUCCESS, NULL); 20 | } 21 | -------------------------------------------------------------------------------- /sway/commands/input/xkb_rules.c: -------------------------------------------------------------------------------- 1 | #include "sway/config.h" 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | 5 | struct cmd_results *input_cmd_xkb_rules(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "xkb_rules", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | struct input_config *ic = config->handler_context.input_config; 11 | if (!ic) { 12 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 13 | } 14 | 15 | ic->xkb_rules = strdup(argv[0]); 16 | 17 | sway_log(SWAY_DEBUG, "set-xkb_rules for config: %s rules: %s", 18 | ic->identifier, ic->xkb_rules); 19 | return cmd_results_new(CMD_SUCCESS, NULL); 20 | } 21 | -------------------------------------------------------------------------------- /sway/commands/input/xkb_variant.c: -------------------------------------------------------------------------------- 1 | #include "sway/config.h" 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | 5 | struct cmd_results *input_cmd_xkb_variant(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "xkb_variant", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | struct input_config *ic = config->handler_context.input_config; 11 | if (!ic) { 12 | return cmd_results_new(CMD_FAILURE, "No input device defined."); 13 | } 14 | 15 | ic->xkb_variant = strdup(argv[0]); 16 | 17 | sway_log(SWAY_DEBUG, "set-xkb_variant for config: %s variant: %s", 18 | ic->identifier, ic->xkb_variant); 19 | return cmd_results_new(CMD_SUCCESS, NULL); 20 | } 21 | -------------------------------------------------------------------------------- /sway/commands/kill.c: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "sway/input/input-manager.h" 3 | #include "sway/input/seat.h" 4 | #include "sway/tree/container.h" 5 | #include "sway/tree/view.h" 6 | #include "sway/tree/workspace.h" 7 | #include "sway/commands.h" 8 | 9 | static void close_container_iterator(struct sway_container *con, void *data) { 10 | if (con->view) { 11 | view_close(con->view); 12 | } 13 | } 14 | 15 | struct cmd_results *cmd_kill(int argc, char **argv) { 16 | if (!root->outputs->length) { 17 | return cmd_results_new(CMD_INVALID, 18 | "Can't run this command while there's no outputs connected."); 19 | } 20 | struct sway_container *con = config->handler_context.container; 21 | struct sway_workspace *ws = config->handler_context.workspace; 22 | 23 | if (con) { 24 | close_container_iterator(con, NULL); 25 | container_for_each_child(con, close_container_iterator, NULL); 26 | } else { 27 | workspace_for_each_container(ws, close_container_iterator, NULL); 28 | } 29 | 30 | return cmd_results_new(CMD_SUCCESS, NULL); 31 | } 32 | -------------------------------------------------------------------------------- /sway/commands/mark.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/tree/view.h" 5 | #include "list.h" 6 | #include "log.h" 7 | #include "stringop.h" 8 | 9 | // mark foo Same as mark --replace foo 10 | // mark --add foo Add this mark to view's list 11 | // mark --replace foo Replace view's marks with this single one 12 | // mark --add --toggle foo Toggle current mark and persist other marks 13 | // mark --replace --toggle foo Toggle current mark and remove other marks 14 | 15 | struct cmd_results *cmd_mark(int argc, char **argv) { 16 | struct cmd_results *error = NULL; 17 | if ((error = checkarg(argc, "mark", EXPECTED_AT_LEAST, 1))) { 18 | return error; 19 | } 20 | struct sway_container *container = config->handler_context.container; 21 | if (!container) { 22 | return cmd_results_new(CMD_INVALID, "Only containers can have marks"); 23 | } 24 | 25 | bool add = false, toggle = false; 26 | while (argc > 0 && has_prefix(*argv, "--")) { 27 | if (strcmp(*argv, "--add") == 0) { 28 | add = true; 29 | } else if (strcmp(*argv, "--replace") == 0) { 30 | add = false; 31 | } else if (strcmp(*argv, "--toggle") == 0) { 32 | toggle = true; 33 | } else { 34 | return cmd_results_new(CMD_INVALID, 35 | "Unrecognized argument '%s'", *argv); 36 | } 37 | ++argv; 38 | --argc; 39 | } 40 | 41 | if (!argc) { 42 | return cmd_results_new(CMD_INVALID, 43 | "Expected '[--add|--replace] [--toggle] '"); 44 | } 45 | 46 | char *mark = join_args(argv, argc); 47 | bool had_mark = container_has_mark(container, mark); 48 | 49 | if (!add) { 50 | // Replacing 51 | container_clear_marks(container); 52 | } 53 | 54 | container_find_and_unmark(mark); 55 | 56 | if (!toggle || !had_mark) { 57 | container_add_mark(container, mark); 58 | } 59 | 60 | free(mark); 61 | container_update_marks(container); 62 | if (container->view) { 63 | view_execute_criteria(container->view); 64 | } 65 | 66 | return cmd_results_new(CMD_SUCCESS, NULL); 67 | } 68 | -------------------------------------------------------------------------------- /sway/commands/max_render_time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/tree/view.h" 5 | 6 | struct cmd_results *cmd_max_render_time(int argc, char **argv) { 7 | if (!argc) { 8 | return cmd_results_new(CMD_INVALID, "Missing max render time argument."); 9 | } 10 | 11 | int max_render_time; 12 | if (!strcmp(*argv, "off")) { 13 | max_render_time = 0; 14 | } else { 15 | char *end; 16 | max_render_time = strtol(*argv, &end, 10); 17 | if (*end || max_render_time <= 0) { 18 | return cmd_results_new(CMD_INVALID, "Invalid max render time."); 19 | } 20 | } 21 | 22 | struct sway_container *container = config->handler_context.container; 23 | if (!container || !container->view) { 24 | return cmd_results_new(CMD_INVALID, 25 | "Only views can have a max_render_time"); 26 | } 27 | 28 | struct sway_view *view = container->view; 29 | view->max_render_time = max_render_time; 30 | 31 | return cmd_results_new(CMD_SUCCESS, NULL); 32 | } 33 | -------------------------------------------------------------------------------- /sway/commands/mouse_warping.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | 5 | struct cmd_results *cmd_mouse_warping(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } else if (strcasecmp(argv[0], "container") == 0) { 10 | config->mouse_warping = WARP_CONTAINER; 11 | } else if (strcasecmp(argv[0], "output") == 0) { 12 | config->mouse_warping = WARP_OUTPUT; 13 | } else if (strcasecmp(argv[0], "none") == 0) { 14 | config->mouse_warping = WARP_NO; 15 | } else { 16 | return cmd_results_new(CMD_FAILURE, 17 | "Expected 'mouse_warping output|container|none'"); 18 | } 19 | return cmd_results_new(CMD_SUCCESS, NULL); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /sway/commands/new_float.c: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | 5 | struct cmd_results *cmd_new_float(int argc, char **argv) { 6 | sway_log(SWAY_INFO, "Warning: new_float is deprecated. " 7 | "Use default_floating_border instead."); 8 | if (config->reading) { 9 | config_add_swaynag_warning("new_float is deprecated. " 10 | "Use default_floating_border instead."); 11 | } 12 | return cmd_default_floating_border(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /sway/commands/new_window.c: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | 5 | struct cmd_results *cmd_new_window(int argc, char **argv) { 6 | sway_log(SWAY_INFO, "Warning: new_window is deprecated. " 7 | "Use default_border instead."); 8 | if (config->reading) { 9 | config_add_swaynag_warning("new_window is deprecated. " 10 | "Use default_border instead."); 11 | } 12 | return cmd_default_border(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /sway/commands/no_focus.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/criteria.h" 4 | #include "list.h" 5 | #include "log.h" 6 | 7 | struct cmd_results *cmd_no_focus(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "no_focus", EXPECTED_AT_LEAST, 1))) { 10 | return error; 11 | } 12 | 13 | char *err_str = NULL; 14 | struct criteria *criteria = criteria_parse(argv[0], &err_str); 15 | if (!criteria) { 16 | error = cmd_results_new(CMD_INVALID, "%s", err_str); 17 | free(err_str); 18 | return error; 19 | } 20 | 21 | 22 | criteria->type = CT_NO_FOCUS; 23 | 24 | // Check if it already exists 25 | if (criteria_already_exists(criteria)) { 26 | sway_log(SWAY_DEBUG, "no_focus already exists: '%s'", criteria->raw); 27 | criteria_destroy(criteria); 28 | return cmd_results_new(CMD_SUCCESS, NULL); 29 | } 30 | 31 | list_add(config->criteria, criteria); 32 | 33 | return cmd_results_new(CMD_SUCCESS, NULL); 34 | } 35 | -------------------------------------------------------------------------------- /sway/commands/nop.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | 3 | struct cmd_results *cmd_nop(int argc, char **argv) { 4 | return cmd_results_new(CMD_SUCCESS, NULL); 5 | } 6 | -------------------------------------------------------------------------------- /sway/commands/opacity.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "sway/commands.h" 5 | #include "sway/tree/container.h" 6 | #include "sway/output.h" 7 | #include "log.h" 8 | 9 | struct cmd_results *cmd_opacity(int argc, char **argv) { 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "opacity", EXPECTED_AT_LEAST, 1))) { 12 | return error; 13 | } 14 | 15 | struct sway_container *con = config->handler_context.container; 16 | 17 | if (con == NULL) { 18 | return cmd_results_new(CMD_FAILURE, "No current container"); 19 | } 20 | 21 | char *err; 22 | float val = strtof(argc == 1 ? argv[0] : argv[1], &err); 23 | if (*err) { 24 | return cmd_results_new(CMD_INVALID, "opacity float invalid"); 25 | } 26 | 27 | if (!strcasecmp(argv[0], "plus")) { 28 | val = con->alpha + val; 29 | } else if (!strcasecmp(argv[0], "minus")) { 30 | val = con->alpha - val; 31 | } else if (argc > 1 && strcasecmp(argv[0], "set")) { 32 | return cmd_results_new(CMD_INVALID, 33 | "Expected: set|plus|minus <0..1>: %s", argv[0]); 34 | } 35 | 36 | if (val < 0 || val > 1) { 37 | return cmd_results_new(CMD_FAILURE, "opacity value out of bounds"); 38 | } 39 | 40 | con->alpha = val; 41 | output_configure_scene(NULL, &con->scene_tree->node, 1); 42 | container_update(con); 43 | 44 | return cmd_results_new(CMD_SUCCESS, NULL); 45 | } 46 | -------------------------------------------------------------------------------- /sway/commands/output/adaptive_sync.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/output.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *output_cmd_adaptive_sync(int argc, char **argv) { 8 | if (!config->handler_context.output_config) { 9 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 10 | } 11 | if (argc == 0) { 12 | return cmd_results_new(CMD_INVALID, "Missing adaptive_sync argument"); 13 | } 14 | 15 | bool current_value = true; 16 | if (strcasecmp(argv[0], "toggle") == 0) { 17 | const char *oc_name = config->handler_context.output_config->name; 18 | if (strcmp(oc_name, "*") == 0) { 19 | return cmd_results_new(CMD_INVALID, 20 | "Cannot apply toggle to all outputs"); 21 | } 22 | 23 | struct sway_output *sway_output = all_output_by_name_or_id(oc_name); 24 | if (!sway_output || !sway_output->wlr_output) { 25 | return cmd_results_new(CMD_FAILURE, 26 | "Cannot apply toggle to unknown output %s", oc_name); 27 | } 28 | 29 | current_value = 30 | sway_output->wlr_output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED; 31 | } 32 | 33 | config->handler_context.output_config->adaptive_sync = parse_boolean(argv[0], current_value); 34 | 35 | config->handler_context.leftovers.argc = argc - 1; 36 | config->handler_context.leftovers.argv = argv + 1; 37 | return NULL; 38 | } 39 | -------------------------------------------------------------------------------- /sway/commands/output/allow_tearing.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | #include "util.h" 4 | 5 | struct cmd_results *output_cmd_allow_tearing(int argc, char **argv) { 6 | if (!config->handler_context.output_config) { 7 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 8 | } 9 | if (argc == 0) { 10 | return cmd_results_new(CMD_INVALID, "Missing allow_tearing argument"); 11 | } 12 | 13 | if (parse_boolean(argv[0], 14 | (config->handler_context.output_config->allow_tearing == 1))) { 15 | config->handler_context.output_config->allow_tearing = 1; 16 | } else { 17 | config->handler_context.output_config->allow_tearing = 0; 18 | } 19 | 20 | config->handler_context.leftovers.argc = argc - 1; 21 | config->handler_context.leftovers.argv = argv + 1; 22 | return NULL; 23 | } 24 | -------------------------------------------------------------------------------- /sway/commands/output/disable.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | 4 | struct cmd_results *output_cmd_disable(int argc, char **argv) { 5 | if (!config->handler_context.output_config) { 6 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 7 | } 8 | config->handler_context.output_config->enabled = 0; 9 | 10 | config->handler_context.leftovers.argc = argc; 11 | config->handler_context.leftovers.argv = argv; 12 | return NULL; 13 | } 14 | -------------------------------------------------------------------------------- /sway/commands/output/dpms.c: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "sway/commands.h" 3 | 4 | struct cmd_results *output_cmd_dpms(int argc, char **argv) { 5 | sway_log(SWAY_INFO, "The \"output dpms\" command is deprecated, " 6 | "use \"output power\" instead"); 7 | return output_cmd_power(argc, argv); 8 | } 9 | -------------------------------------------------------------------------------- /sway/commands/output/enable.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | 4 | struct cmd_results *output_cmd_enable(int argc, char **argv) { 5 | if (!config->handler_context.output_config) { 6 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 7 | } 8 | 9 | config->handler_context.output_config->enabled = 1; 10 | 11 | config->handler_context.leftovers.argc = argc; 12 | config->handler_context.leftovers.argv = argv; 13 | return NULL; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /sway/commands/output/max_render_time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | 5 | struct cmd_results *output_cmd_max_render_time(int argc, char **argv) { 6 | if (!config->handler_context.output_config) { 7 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 8 | } 9 | if (!argc) { 10 | return cmd_results_new(CMD_INVALID, "Missing max render time argument."); 11 | } 12 | 13 | int max_render_time; 14 | if (!strcmp(*argv, "off")) { 15 | max_render_time = 0; 16 | } else { 17 | char *end; 18 | max_render_time = strtol(*argv, &end, 10); 19 | if (*end || max_render_time <= 0) { 20 | return cmd_results_new(CMD_INVALID, "Invalid max render time."); 21 | } 22 | } 23 | config->handler_context.output_config->max_render_time = max_render_time; 24 | 25 | config->handler_context.leftovers.argc = argc - 1; 26 | config->handler_context.leftovers.argv = argv + 1; 27 | return NULL; 28 | } 29 | -------------------------------------------------------------------------------- /sway/commands/output/position.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | 5 | struct cmd_results *output_cmd_position(int argc, char **argv) { 6 | if (!config->handler_context.output_config) { 7 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 8 | } 9 | if (!argc) { 10 | return cmd_results_new(CMD_INVALID, "Missing position argument."); 11 | } 12 | 13 | char *end; 14 | config->handler_context.output_config->x = strtol(*argv, &end, 10); 15 | if (*end) { 16 | // Format is 1234,4321 17 | if (*end != ',') { 18 | return cmd_results_new(CMD_INVALID, "Invalid position x."); 19 | } 20 | ++end; 21 | config->handler_context.output_config->y = strtol(end, &end, 10); 22 | if (*end) { 23 | return cmd_results_new(CMD_INVALID, "Invalid position y."); 24 | } 25 | } else { 26 | // Format is 1234 4321 (legacy) 27 | argc--; argv++; 28 | if (!argc) { 29 | return cmd_results_new(CMD_INVALID, "Missing position argument (y)."); 30 | } 31 | config->handler_context.output_config->y = strtol(*argv, &end, 10); 32 | if (*end) { 33 | return cmd_results_new(CMD_INVALID, "Invalid position y."); 34 | } 35 | } 36 | 37 | config->handler_context.leftovers.argc = argc - 1; 38 | config->handler_context.leftovers.argv = argv + 1; 39 | return NULL; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /sway/commands/output/power.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/output.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *output_cmd_power(int argc, char **argv) { 8 | if (!config->handler_context.output_config) { 9 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 10 | } 11 | if (argc == 0) { 12 | return cmd_results_new(CMD_INVALID, "Missing power argument"); 13 | } 14 | 15 | bool current = true; 16 | if (strcasecmp(argv[0], "toggle") == 0) { 17 | const char *oc_name = config->handler_context.output_config->name; 18 | if (strcmp(oc_name, "*") == 0) { 19 | return cmd_results_new(CMD_INVALID, 20 | "Cannot apply toggle to all outputs"); 21 | } 22 | 23 | struct sway_output *sway_output = all_output_by_name_or_id(oc_name); 24 | if (!sway_output || !sway_output->wlr_output) { 25 | return cmd_results_new(CMD_FAILURE, 26 | "Cannot apply toggle to unknown output %s", oc_name); 27 | } 28 | 29 | if (sway_output->enabled && !sway_output->wlr_output->enabled) { 30 | current = false; 31 | } 32 | } 33 | 34 | if (parse_boolean(argv[0], current)) { 35 | config->handler_context.output_config->power = 1; 36 | } else { 37 | config->handler_context.output_config->power = 0; 38 | } 39 | 40 | config->handler_context.leftovers.argc = argc - 1; 41 | config->handler_context.leftovers.argv = argv + 1; 42 | return NULL; 43 | } 44 | -------------------------------------------------------------------------------- /sway/commands/output/render_bit_depth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | 6 | struct cmd_results *output_cmd_render_bit_depth(int argc, char **argv) { 7 | if (!config->handler_context.output_config) { 8 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 9 | } 10 | if (!argc) { 11 | return cmd_results_new(CMD_INVALID, "Missing bit depth argument."); 12 | } 13 | 14 | if (strcmp(*argv, "6") == 0) { 15 | config->handler_context.output_config->render_bit_depth = 16 | RENDER_BIT_DEPTH_6; 17 | } else if (strcmp(*argv, "8") == 0) { 18 | config->handler_context.output_config->render_bit_depth = 19 | RENDER_BIT_DEPTH_8; 20 | } else if (strcmp(*argv, "10") == 0) { 21 | config->handler_context.output_config->render_bit_depth = 22 | RENDER_BIT_DEPTH_10; 23 | } else { 24 | return cmd_results_new(CMD_INVALID, 25 | "Invalid bit depth. Must be a value in (6|8|10)."); 26 | } 27 | 28 | config->handler_context.leftovers.argc = argc - 1; 29 | config->handler_context.leftovers.argv = argv + 1; 30 | return NULL; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /sway/commands/output/scale.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | 5 | struct cmd_results *output_cmd_scale(int argc, char **argv) { 6 | if (!config->handler_context.output_config) { 7 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 8 | } 9 | if (!argc) { 10 | return cmd_results_new(CMD_INVALID, "Missing scale argument."); 11 | } 12 | 13 | char *end; 14 | config->handler_context.output_config->scale = strtof(*argv, &end); 15 | if (*end) { 16 | return cmd_results_new(CMD_INVALID, "Invalid scale."); 17 | } 18 | 19 | config->handler_context.leftovers.argc = argc - 1; 20 | config->handler_context.leftovers.argv = argv + 1; 21 | return NULL; 22 | } 23 | -------------------------------------------------------------------------------- /sway/commands/output/scale_filter.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "log.h" 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "sway/output.h" 6 | 7 | struct cmd_results *output_cmd_scale_filter(int argc, char **argv) { 8 | if (!config->handler_context.output_config) { 9 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 10 | } 11 | 12 | if (!argc) { 13 | return cmd_results_new(CMD_INVALID, "Missing scale_filter argument."); 14 | } 15 | 16 | 17 | enum scale_filter_mode scale_filter; 18 | if (strcmp(*argv, "linear") == 0) { 19 | scale_filter = SCALE_FILTER_LINEAR; 20 | } else if (strcmp(*argv, "nearest") == 0) { 21 | scale_filter = SCALE_FILTER_NEAREST; 22 | } else if (strcmp(*argv, "smart") == 0) { 23 | scale_filter = SCALE_FILTER_SMART; 24 | } else { 25 | return cmd_results_new(CMD_INVALID, "Invalid output scale_filter."); 26 | } 27 | 28 | struct output_config *oc = config->handler_context.output_config; 29 | config->handler_context.leftovers.argc = argc - 1; 30 | config->handler_context.leftovers.argv = argv + 1; 31 | 32 | oc->scale_filter = scale_filter; 33 | return NULL; 34 | } 35 | -------------------------------------------------------------------------------- /sway/commands/output/subpixel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "log.h" 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "sway/output.h" 6 | 7 | struct cmd_results *output_cmd_subpixel(int argc, char **argv) { 8 | if (!config->handler_context.output_config) { 9 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 10 | } 11 | if (!argc) { 12 | return cmd_results_new(CMD_INVALID, "Missing subpixel argument."); 13 | } 14 | enum wl_output_subpixel subpixel; 15 | 16 | if (strcmp(*argv, "rgb") == 0) { 17 | subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB; 18 | } else if (strcmp(*argv, "bgr") == 0) { 19 | subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR; 20 | } else if (strcmp(*argv, "vrgb") == 0) { 21 | subpixel = WL_OUTPUT_SUBPIXEL_VERTICAL_RGB; 22 | } else if (strcmp(*argv, "vbgr") == 0) { 23 | subpixel = WL_OUTPUT_SUBPIXEL_VERTICAL_BGR; 24 | } else if (strcmp(*argv, "none") == 0) { 25 | subpixel = WL_OUTPUT_SUBPIXEL_NONE; 26 | } else { 27 | return cmd_results_new(CMD_INVALID, "Invalid output subpixel."); 28 | } 29 | 30 | struct output_config *oc = config->handler_context.output_config; 31 | config->handler_context.leftovers.argc = argc - 1; 32 | config->handler_context.leftovers.argv = argv + 1; 33 | 34 | oc->subpixel = subpixel; 35 | return NULL; 36 | } 37 | -------------------------------------------------------------------------------- /sway/commands/output/toggle.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | #include "sway/output.h" 4 | 5 | struct cmd_results *output_cmd_toggle(int argc, char **argv) { 6 | if (!config->handler_context.output_config) { 7 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 8 | } 9 | 10 | struct output_config *oc = config->handler_context.output_config; 11 | 12 | if (strcmp(oc->name, "*") == 0) { 13 | return cmd_results_new(CMD_INVALID, 14 | "Cannot apply toggle to all outputs."); 15 | } 16 | 17 | struct sway_output *sway_output = all_output_by_name_or_id(oc->name); 18 | 19 | if (sway_output == NULL) { 20 | return cmd_results_new(CMD_FAILURE, 21 | "Cannot apply toggle to unknown output %s", oc->name); 22 | } 23 | 24 | oc = find_output_config(sway_output); 25 | 26 | if (!oc || oc->enabled != 0) { 27 | config->handler_context.output_config->enabled = 0; 28 | } else { 29 | config->handler_context.output_config->enabled = 1; 30 | } 31 | 32 | free_output_config(oc); 33 | config->handler_context.leftovers.argc = argc; 34 | config->handler_context.leftovers.argv = argv; 35 | return NULL; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /sway/commands/output/unplug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #if WLR_HAS_X11_BACKEND 6 | #include 7 | #endif 8 | #include "sway/commands.h" 9 | #include "sway/config.h" 10 | #include "sway/output.h" 11 | 12 | static bool is_backend_allowed(struct wlr_backend *backend) { 13 | if (wlr_backend_is_headless(backend)) { 14 | return true; 15 | } 16 | if (wlr_backend_is_wl(backend)) { 17 | return true; 18 | } 19 | #if WLR_HAS_X11_BACKEND 20 | if (wlr_backend_is_x11(backend)) { 21 | return true; 22 | } 23 | #endif 24 | return false; 25 | } 26 | 27 | /** 28 | * This command is intended for developer use only. 29 | */ 30 | struct cmd_results *output_cmd_unplug(int argc, char **argv) { 31 | if (!config->handler_context.output_config) { 32 | return cmd_results_new(CMD_FAILURE, "Missing output config"); 33 | } 34 | 35 | const char *oc_name = config->handler_context.output_config->name; 36 | if (strcmp(oc_name, "*") == 0) { 37 | return cmd_results_new(CMD_INVALID, "Won't unplug all outputs"); 38 | } 39 | 40 | struct sway_output *sway_output = all_output_by_name_or_id(oc_name); 41 | if (!sway_output) { 42 | return cmd_results_new(CMD_INVALID, 43 | "Cannot unplug unknown output %s", oc_name); 44 | } 45 | 46 | if (!is_backend_allowed(sway_output->wlr_output->backend)) { 47 | return cmd_results_new(CMD_INVALID, 48 | "Can only unplug outputs with headless, wayland or x11 backend"); 49 | } 50 | 51 | wlr_output_destroy(sway_output->wlr_output); 52 | 53 | return cmd_results_new(CMD_SUCCESS, NULL); 54 | } 55 | -------------------------------------------------------------------------------- /sway/commands/popup_during_fullscreen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | 5 | struct cmd_results *cmd_popup_during_fullscreen(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "popup_during_fullscreen", 8 | EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | 12 | if (strcasecmp(argv[0], "smart") == 0) { 13 | config->popup_during_fullscreen = POPUP_SMART; 14 | } else if (strcasecmp(argv[0], "ignore") == 0) { 15 | config->popup_during_fullscreen = POPUP_IGNORE; 16 | } else if (strcasecmp(argv[0], "leave_fullscreen") == 0) { 17 | config->popup_during_fullscreen = POPUP_LEAVE; 18 | } else { 19 | return cmd_results_new(CMD_INVALID, "Expected " 20 | "'popup_during_fullscreen smart|ignore|leave_fullscreen'"); 21 | } 22 | 23 | return cmd_results_new(CMD_SUCCESS, NULL); 24 | } 25 | -------------------------------------------------------------------------------- /sway/commands/primary_selection.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/config.h" 4 | #include "sway/commands.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *cmd_primary_selection(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "primary_selection", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | 13 | bool primary_selection = parse_boolean(argv[0], true); 14 | 15 | // config->primary_selection is reset to the previous value on reload in 16 | // load_main_config() 17 | if (config->reloading && config->primary_selection != primary_selection) { 18 | return cmd_results_new(CMD_FAILURE, 19 | "primary_selection can only be enabled/disabled at launch"); 20 | } 21 | 22 | config->primary_selection = primary_selection; 23 | 24 | return cmd_results_new(CMD_SUCCESS, NULL); 25 | } 26 | -------------------------------------------------------------------------------- /sway/commands/seat/attach.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "stringop.h" 5 | 6 | struct cmd_results *seat_cmd_attach(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "attach", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | if (!config->handler_context.seat_config) { 12 | return cmd_results_new(CMD_FAILURE, "No seat defined"); 13 | } 14 | if (!config->active) { 15 | return cmd_results_new(CMD_DEFER, NULL); 16 | } 17 | 18 | struct seat_attachment_config *attachment = seat_attachment_config_new(); 19 | if (!attachment) { 20 | return cmd_results_new(CMD_FAILURE, 21 | "Failed to allocate seat attachment config"); 22 | } 23 | attachment->identifier = strdup(argv[0]); 24 | list_add(config->handler_context.seat_config->attachments, attachment); 25 | 26 | return cmd_results_new(CMD_SUCCESS, NULL); 27 | } 28 | -------------------------------------------------------------------------------- /sway/commands/seat/fallback.c: -------------------------------------------------------------------------------- 1 | #include "sway/config.h" 2 | #include "sway/commands.h" 3 | #include "util.h" 4 | 5 | struct cmd_results *seat_cmd_fallback(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "fallback", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | if (!config->handler_context.seat_config) { 11 | return cmd_results_new(CMD_FAILURE, "No seat defined"); 12 | } 13 | 14 | config->handler_context.seat_config->fallback = 15 | parse_boolean(argv[0], false); 16 | 17 | return cmd_results_new(CMD_SUCCESS, NULL); 18 | } 19 | -------------------------------------------------------------------------------- /sway/commands/seat/hide_cursor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/input/seat.h" 5 | #include "sway/input/cursor.h" 6 | #include "sway/server.h" 7 | #include "stringop.h" 8 | #include "util.h" 9 | 10 | struct cmd_results *seat_cmd_hide_cursor(int argc, char **argv) { 11 | struct cmd_results *error = NULL; 12 | if ((error = checkarg(argc, "hide_cursor", EXPECTED_AT_LEAST, 1))) { 13 | return error; 14 | } 15 | if ((error = checkarg(argc, "hide_cursor", EXPECTED_AT_MOST, 2))) { 16 | return error; 17 | } 18 | struct seat_config *seat_config = config->handler_context.seat_config; 19 | if (!seat_config) { 20 | return cmd_results_new(CMD_FAILURE, "No seat defined"); 21 | } 22 | 23 | if (argc == 1) { 24 | char *end; 25 | int timeout = strtol(argv[0], &end, 10); 26 | if (*end) { 27 | return cmd_results_new(CMD_INVALID, "Expected an integer timeout"); 28 | } 29 | if (timeout < 100 && timeout != 0) { 30 | timeout = 100; 31 | } 32 | seat_config->hide_cursor_timeout = timeout; 33 | } else { 34 | if (strcmp(argv[0], "when-typing") != 0) { 35 | return cmd_results_new(CMD_INVALID, 36 | "Expected 'hide_cursor |when-typing [enable|disable]'"); 37 | } 38 | seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ? 39 | HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE; 40 | 41 | // Invalidate all the caches for this config 42 | struct sway_seat *seat = NULL; 43 | wl_list_for_each(seat, &server.input->seats, link) { 44 | seat->cursor->hide_when_typing = HIDE_WHEN_TYPING_DEFAULT; 45 | } 46 | } 47 | 48 | return cmd_results_new(CMD_SUCCESS, NULL); 49 | } 50 | -------------------------------------------------------------------------------- /sway/commands/seat/keyboard_grouping.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "stringop.h" 5 | 6 | struct cmd_results *seat_cmd_keyboard_grouping(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "keyboard_grouping", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | if (!config->handler_context.seat_config) { 12 | return cmd_results_new(CMD_INVALID, "No seat defined"); 13 | } 14 | 15 | struct seat_config *seat_config = config->handler_context.seat_config; 16 | if (strcmp(argv[0], "none") == 0) { 17 | seat_config->keyboard_grouping = KEYBOARD_GROUP_NONE; 18 | } else if (strcmp(argv[0], "smart") == 0) { 19 | seat_config->keyboard_grouping = KEYBOARD_GROUP_SMART; 20 | } else { 21 | return cmd_results_new(CMD_INVALID, 22 | "Expected syntax `keyboard_grouping none|smart`"); 23 | } 24 | 25 | return cmd_results_new(CMD_SUCCESS, NULL); 26 | } 27 | -------------------------------------------------------------------------------- /sway/commands/seat/pointer_constraint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "sway/input/cursor.h" 6 | #include "sway/input/seat.h" 7 | #include "sway/server.h" 8 | 9 | enum operation { 10 | OP_ENABLE, 11 | OP_DISABLE, 12 | OP_ESCAPE, 13 | }; 14 | 15 | // pointer_constraint [enable|disable|escape] 16 | struct cmd_results *seat_cmd_pointer_constraint(int argc, char **argv) { 17 | struct cmd_results *error = NULL; 18 | if ((error = checkarg(argc, "pointer_constraint", EXPECTED_EQUAL_TO, 1))) { 19 | return error; 20 | } 21 | if (!config->handler_context.seat_config) { 22 | return cmd_results_new(CMD_FAILURE, "No seat defined"); 23 | } 24 | 25 | enum operation op; 26 | if (strcmp(argv[0], "enable") == 0) { 27 | op = OP_ENABLE; 28 | } else if (strcmp(argv[0], "disable") == 0) { 29 | op = OP_DISABLE; 30 | } else if (strcmp(argv[0], "escape") == 0) { 31 | op = OP_ESCAPE; 32 | } else { 33 | return cmd_results_new(CMD_FAILURE, "Expected enable|disable|escape"); 34 | } 35 | 36 | if (op == OP_ESCAPE && config->reading) { 37 | return cmd_results_new(CMD_FAILURE, "Can only escape at runtime."); 38 | } 39 | 40 | struct seat_config *seat_config = config->handler_context.seat_config; 41 | switch (op) { 42 | case OP_ENABLE: 43 | seat_config->allow_constrain = CONSTRAIN_ENABLE; 44 | break; 45 | case OP_DISABLE: 46 | seat_config->allow_constrain = CONSTRAIN_DISABLE; 47 | /* fallthrough */ 48 | case OP_ESCAPE:; 49 | bool wildcard = !strcmp(seat_config->name, "*"); 50 | struct sway_seat *seat = NULL; 51 | wl_list_for_each(seat, &server.input->seats, link) { 52 | if (wildcard || !strcmp(seat->wlr_seat->name, seat_config->name)) { 53 | sway_cursor_constrain(seat->cursor, NULL); 54 | } 55 | } 56 | break; 57 | } 58 | return cmd_results_new(CMD_SUCCESS, NULL); 59 | } 60 | -------------------------------------------------------------------------------- /sway/commands/seat/xcursor_theme.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | 5 | struct cmd_results *seat_cmd_xcursor_theme(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "xcursor_theme", EXPECTED_AT_LEAST, 1)) || 8 | (error = checkarg(argc, "xcursor_theme", EXPECTED_AT_MOST, 2))) { 9 | return error; 10 | } 11 | if (!config->handler_context.seat_config) { 12 | return cmd_results_new(CMD_FAILURE, "No seat defined"); 13 | } 14 | 15 | const char *theme_name = argv[0]; 16 | unsigned size = 24; 17 | 18 | if (argc == 2) { 19 | char *end; 20 | size = strtoul(argv[1], &end, 10); 21 | if (*end) { 22 | return cmd_results_new( 23 | CMD_INVALID, "Expected a positive integer size"); 24 | } 25 | } 26 | 27 | free(config->handler_context.seat_config->xcursor_theme.name); 28 | config->handler_context.seat_config->xcursor_theme.name = strdup(theme_name); 29 | config->handler_context.seat_config->xcursor_theme.size = size; 30 | 31 | return cmd_results_new(CMD_SUCCESS, NULL); 32 | } 33 | -------------------------------------------------------------------------------- /sway/commands/set.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "sway/commands.h" 5 | #include "sway/config.h" 6 | #include "list.h" 7 | #include "log.h" 8 | #include "stringop.h" 9 | 10 | // sort in order of longest->shortest 11 | static int compare_set_qsort(const void *_l, const void *_r) { 12 | struct sway_variable const *l = *(void **)_l; 13 | struct sway_variable const *r = *(void **)_r; 14 | return strlen(r->name) - strlen(l->name); 15 | } 16 | 17 | void free_sway_variable(struct sway_variable *var) { 18 | if (!var) { 19 | return; 20 | } 21 | free(var->name); 22 | free(var->value); 23 | free(var); 24 | } 25 | 26 | struct cmd_results *cmd_set(int argc, char **argv) { 27 | struct cmd_results *error = NULL; 28 | if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) { 29 | return error; 30 | } 31 | 32 | if (argv[0][0] != '$') { 33 | return cmd_results_new(CMD_INVALID, "variable '%s' must start with $", argv[0]); 34 | } 35 | 36 | struct sway_variable *var = NULL; 37 | // Find old variable if it exists 38 | int i; 39 | for (i = 0; i < config->symbols->length; ++i) { 40 | var = config->symbols->items[i]; 41 | if (strcmp(var->name, argv[0]) == 0) { 42 | break; 43 | } 44 | var = NULL; 45 | } 46 | if (var) { 47 | free(var->value); 48 | } else { 49 | var = malloc(sizeof(struct sway_variable)); 50 | if (!var) { 51 | return cmd_results_new(CMD_FAILURE, "Unable to allocate variable"); 52 | } 53 | var->name = strdup(argv[0]); 54 | list_add(config->symbols, var); 55 | list_qsort(config->symbols, compare_set_qsort); 56 | } 57 | var->value = join_args(argv + 1, argc - 1); 58 | return cmd_results_new(CMD_SUCCESS, NULL); 59 | } 60 | -------------------------------------------------------------------------------- /sway/commands/shortcuts_inhibitor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "log.h" 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "sway/input/seat.h" 6 | #include "sway/server.h" 7 | #include "sway/tree/container.h" 8 | #include "sway/tree/view.h" 9 | 10 | struct cmd_results *cmd_shortcuts_inhibitor(int argc, char **argv) { 11 | struct cmd_results *error = NULL; 12 | if ((error = checkarg(argc, "shortcuts_inhibitor", EXPECTED_EQUAL_TO, 1))) { 13 | return error; 14 | } 15 | 16 | struct sway_container *con = config->handler_context.container; 17 | if (!con || !con->view) { 18 | return cmd_results_new(CMD_INVALID, 19 | "Only views can have shortcuts inhibitors"); 20 | } 21 | 22 | struct sway_view *view = con->view; 23 | if (strcmp(argv[0], "enable") == 0) { 24 | view->shortcuts_inhibit = SHORTCUTS_INHIBIT_ENABLE; 25 | } else if (strcmp(argv[0], "disable") == 0) { 26 | view->shortcuts_inhibit = SHORTCUTS_INHIBIT_DISABLE; 27 | 28 | struct sway_seat *seat = NULL; 29 | wl_list_for_each(seat, &server.input->seats, link) { 30 | struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor = 31 | keyboard_shortcuts_inhibitor_get_for_surface( 32 | seat, view->surface); 33 | if (!sway_inhibitor) { 34 | continue; 35 | } 36 | 37 | wlr_keyboard_shortcuts_inhibitor_v1_deactivate( 38 | sway_inhibitor->inhibitor); 39 | sway_log(SWAY_DEBUG, "Deactivated keyboard shortcuts " 40 | "inhibitor for seat %s on view", 41 | seat->wlr_seat->name); 42 | 43 | } 44 | } else { 45 | return cmd_results_new(CMD_INVALID, 46 | "Expected `shortcuts_inhibitor enable|disable`"); 47 | } 48 | 49 | return cmd_results_new(CMD_SUCCESS, NULL); 50 | } 51 | -------------------------------------------------------------------------------- /sway/commands/show_marks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/tree/root.h" 5 | #include "sway/tree/view.h" 6 | #include "sway/output.h" 7 | #include "list.h" 8 | #include "log.h" 9 | #include "stringop.h" 10 | #include "util.h" 11 | 12 | static void title_bar_update_iterator(struct sway_container *con, void *data) { 13 | container_update_marks(con); 14 | } 15 | 16 | struct cmd_results *cmd_show_marks(int argc, char **argv) { 17 | struct cmd_results *error = NULL; 18 | if ((error = checkarg(argc, "show_marks", EXPECTED_AT_LEAST, 1))) { 19 | return error; 20 | } 21 | 22 | config->show_marks = parse_boolean(argv[0], config->show_marks); 23 | 24 | if (config->show_marks) { 25 | root_for_each_container(title_bar_update_iterator, NULL); 26 | } 27 | 28 | return cmd_results_new(CMD_SUCCESS, NULL); 29 | } 30 | -------------------------------------------------------------------------------- /sway/commands/smart_borders.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | #include "sway/tree/arrange.h" 4 | #include "sway/tree/view.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *cmd_smart_borders(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "smart_borders", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | 13 | if (strcmp(argv[0], "no_gaps") == 0) { 14 | config->hide_edge_borders_smart = ESMART_NO_GAPS; 15 | } else { 16 | config->hide_edge_borders_smart = parse_boolean(argv[0], true) ? 17 | ESMART_ON : ESMART_OFF; 18 | } 19 | 20 | arrange_root(); 21 | 22 | return cmd_results_new(CMD_SUCCESS, NULL); 23 | } 24 | -------------------------------------------------------------------------------- /sway/commands/smart_gaps.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/tree/arrange.h" 5 | #include "sway/tree/view.h" 6 | #include "sway/tree/container.h" 7 | #include "log.h" 8 | #include "stringop.h" 9 | #include "util.h" 10 | 11 | struct cmd_results *cmd_smart_gaps(int argc, char **argv) { 12 | struct cmd_results *error = checkarg(argc, "smart_gaps", EXPECTED_AT_LEAST, 1); 13 | 14 | if (error) { 15 | return error; 16 | } 17 | 18 | if (strcmp(argv[0], "inverse_outer") == 0) { 19 | config->smart_gaps = SMART_GAPS_INVERSE_OUTER; 20 | } else { 21 | config->smart_gaps = parse_boolean(argv[0], config->smart_gaps) 22 | ? SMART_GAPS_ON : SMART_GAPS_OFF; 23 | } 24 | 25 | arrange_root(); 26 | 27 | return cmd_results_new(CMD_SUCCESS, NULL); 28 | } 29 | -------------------------------------------------------------------------------- /sway/commands/sticky.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "sway/input/seat.h" 5 | #include "sway/ipc-server.h" 6 | #include "sway/output.h" 7 | #include "sway/tree/arrange.h" 8 | #include "sway/tree/container.h" 9 | #include "sway/tree/view.h" 10 | #include "sway/tree/workspace.h" 11 | #include "list.h" 12 | #include "log.h" 13 | #include "util.h" 14 | 15 | struct cmd_results *cmd_sticky(int argc, char **argv) { 16 | struct cmd_results *error = NULL; 17 | if ((error = checkarg(argc, "sticky", EXPECTED_EQUAL_TO, 1))) { 18 | return error; 19 | } 20 | struct sway_container *container = config->handler_context.container; 21 | 22 | if (container == NULL) { 23 | return cmd_results_new(CMD_FAILURE, "No current container"); 24 | }; 25 | 26 | container->is_sticky = parse_boolean(argv[0], container->is_sticky); 27 | 28 | if (container_is_sticky_or_child(container) && 29 | !container_is_scratchpad_hidden(container)) { 30 | // move container to active workspace 31 | struct sway_workspace *active_workspace = 32 | output_get_active_workspace(container->pending.workspace->output); 33 | if (!sway_assert(active_workspace, 34 | "Expected output to have a workspace")) { 35 | return cmd_results_new(CMD_FAILURE, 36 | "Expected output to have a workspace"); 37 | } 38 | if (container->pending.workspace != active_workspace) { 39 | struct sway_workspace *old_workspace = container->pending.workspace; 40 | container_detach(container); 41 | workspace_add_floating(active_workspace, container); 42 | container_handle_fullscreen_reparent(container); 43 | arrange_workspace(active_workspace); 44 | workspace_consider_destroy(old_workspace); 45 | } 46 | } 47 | 48 | return cmd_results_new(CMD_SUCCESS, NULL); 49 | } 50 | -------------------------------------------------------------------------------- /sway/commands/swaybg_command.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | #include "stringop.h" 5 | 6 | struct cmd_results *cmd_swaybg_command(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "swaybg_command", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | 12 | free(config->swaybg_command); 13 | config->swaybg_command = NULL; 14 | 15 | char *new_command = join_args(argv, argc); 16 | if (strcmp(new_command, "-") != 0) { 17 | config->swaybg_command = new_command; 18 | sway_log(SWAY_DEBUG, "Using custom swaybg command: %s", 19 | config->swaybg_command); 20 | } else { 21 | free(new_command); 22 | } 23 | 24 | return cmd_results_new(CMD_SUCCESS, NULL); 25 | } 26 | -------------------------------------------------------------------------------- /sway/commands/swaynag_command.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "log.h" 4 | #include "stringop.h" 5 | 6 | struct cmd_results *cmd_swaynag_command(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "swaynag_command", EXPECTED_AT_LEAST, 1))) { 9 | return error; 10 | } 11 | 12 | free(config->swaynag_command); 13 | config->swaynag_command = NULL; 14 | 15 | char *new_command = join_args(argv, argc); 16 | if (strcmp(new_command, "-") != 0) { 17 | config->swaynag_command = new_command; 18 | sway_log(SWAY_DEBUG, "Using custom swaynag command: %s", 19 | config->swaynag_command); 20 | } else { 21 | free(new_command); 22 | } 23 | 24 | return cmd_results_new(CMD_SUCCESS, NULL); 25 | } 26 | -------------------------------------------------------------------------------- /sway/commands/tiling_drag.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "util.h" 3 | 4 | struct cmd_results *cmd_tiling_drag(int argc, char **argv) { 5 | struct cmd_results *error = NULL; 6 | if ((error = checkarg(argc, "tiling_drag", EXPECTED_EQUAL_TO, 1))) { 7 | return error; 8 | } 9 | 10 | config->tiling_drag = parse_boolean(argv[0], config->tiling_drag); 11 | 12 | return cmd_results_new(CMD_SUCCESS, NULL); 13 | } 14 | -------------------------------------------------------------------------------- /sway/commands/tiling_drag_threshold.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "log.h" 5 | 6 | struct cmd_results *cmd_tiling_drag_threshold(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "tiling_drag_threshold", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | 12 | char *inv; 13 | int value = strtol(argv[0], &inv, 10); 14 | if (*inv != '\0' || value < 0) { 15 | return cmd_results_new(CMD_INVALID, "Invalid threshold specified"); 16 | } 17 | 18 | config->tiling_drag_threshold = value; 19 | 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/title_align.c: -------------------------------------------------------------------------------- 1 | #include "sway/commands.h" 2 | #include "sway/config.h" 3 | #include "sway/output.h" 4 | #include "sway/tree/container.h" 5 | #include "sway/tree/root.h" 6 | 7 | static void arrange_title_bar_iterator(struct sway_container *con, void *data) { 8 | container_arrange_title_bar(con); 9 | } 10 | 11 | struct cmd_results *cmd_title_align(int argc, char **argv) { 12 | struct cmd_results *error = NULL; 13 | if ((error = checkarg(argc, "title_align", EXPECTED_AT_LEAST, 1))) { 14 | return error; 15 | } 16 | 17 | if (strcmp(argv[0], "left") == 0) { 18 | config->title_align = ALIGN_LEFT; 19 | } else if (strcmp(argv[0], "center") == 0) { 20 | config->title_align = ALIGN_CENTER; 21 | } else if (strcmp(argv[0], "right") == 0) { 22 | config->title_align = ALIGN_RIGHT; 23 | } else { 24 | return cmd_results_new(CMD_INVALID, 25 | "Expected 'title_align left|center|right'"); 26 | } 27 | 28 | root_for_each_container(arrange_title_bar_iterator, NULL); 29 | 30 | return cmd_results_new(CMD_SUCCESS, NULL); 31 | } 32 | -------------------------------------------------------------------------------- /sway/commands/title_format.c: -------------------------------------------------------------------------------- 1 | #define _POSIX_C_SOURCE 200809L 2 | #include 3 | #include "sway/commands.h" 4 | #include "sway/config.h" 5 | #include "sway/tree/view.h" 6 | #include "log.h" 7 | #include "stringop.h" 8 | 9 | struct cmd_results *cmd_title_format(int argc, char **argv) { 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "title_format", EXPECTED_AT_LEAST, 1))) { 12 | return error; 13 | } 14 | struct sway_container *container = config->handler_context.container; 15 | if (!container) { 16 | return cmd_results_new(CMD_INVALID, 17 | "Only valid containers can have a title_format"); 18 | } 19 | char *format = join_args(argv, argc); 20 | if (container->title_format) { 21 | free(container->title_format); 22 | } 23 | container->title_format = format; 24 | if (container->view) { 25 | view_update_title(container->view, true); 26 | } else { 27 | container_update_representation(container); 28 | } 29 | return cmd_results_new(CMD_SUCCESS, NULL); 30 | } 31 | -------------------------------------------------------------------------------- /sway/commands/titlebar_border_thickness.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/output.h" 5 | #include "sway/tree/arrange.h" 6 | #include "log.h" 7 | 8 | struct cmd_results *cmd_titlebar_border_thickness(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "titlebar_border_thickness", EXPECTED_EQUAL_TO, 1))) { 11 | return error; 12 | } 13 | 14 | char *inv; 15 | int value = strtol(argv[0], &inv, 10); 16 | if (*inv != '\0' || value < 0 || value > config->titlebar_v_padding) { 17 | return cmd_results_new(CMD_FAILURE, "Invalid size specified"); 18 | } 19 | 20 | config->titlebar_border_thickness = value; 21 | 22 | for (int i = 0; i < root->outputs->length; ++i) { 23 | struct sway_output *output = root->outputs->items[i]; 24 | struct sway_workspace *ws = output_get_active_workspace(output); 25 | if (!sway_assert(ws, "Expected output to have a workspace")) { 26 | return cmd_results_new(CMD_FAILURE, 27 | "Expected output to have a workspace"); 28 | } 29 | arrange_workspace(ws); 30 | } 31 | 32 | return cmd_results_new(CMD_SUCCESS, NULL); 33 | } 34 | -------------------------------------------------------------------------------- /sway/commands/titlebar_padding.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/output.h" 5 | #include "sway/tree/arrange.h" 6 | #include "log.h" 7 | 8 | struct cmd_results *cmd_titlebar_padding(int argc, char **argv) { 9 | struct cmd_results *error = NULL; 10 | if ((error = checkarg(argc, "titlebar_padding", EXPECTED_AT_LEAST, 1))) { 11 | return error; 12 | } 13 | 14 | char *inv; 15 | int h_value = strtol(argv[0], &inv, 10); 16 | if (*inv != '\0' || h_value < 0 || h_value < config->titlebar_border_thickness) { 17 | return cmd_results_new(CMD_FAILURE, "Invalid size specified"); 18 | } 19 | 20 | int v_value; 21 | if (argc == 1) { 22 | v_value = h_value; 23 | } else { 24 | v_value = strtol(argv[1], &inv, 10); 25 | if (*inv != '\0' || v_value < 0 || v_value < config->titlebar_border_thickness) { 26 | return cmd_results_new(CMD_FAILURE, "Invalid size specified"); 27 | } 28 | } 29 | 30 | config->titlebar_v_padding = v_value; 31 | config->titlebar_h_padding = h_value; 32 | 33 | for (int i = 0; i < root->outputs->length; ++i) { 34 | struct sway_output *output = root->outputs->items[i]; 35 | arrange_workspace(output_get_active_workspace(output)); 36 | } 37 | 38 | return cmd_results_new(CMD_SUCCESS, NULL); 39 | } 40 | -------------------------------------------------------------------------------- /sway/commands/unmark.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/tree/root.h" 5 | #include "sway/tree/view.h" 6 | #include "list.h" 7 | #include "log.h" 8 | #include "stringop.h" 9 | 10 | static void remove_mark(struct sway_container *con) { 11 | container_clear_marks(con); 12 | container_update_marks(con); 13 | } 14 | 15 | static void remove_all_marks_iterator(struct sway_container *con, void *data) { 16 | remove_mark(con); 17 | } 18 | 19 | // unmark Remove all marks from all views 20 | // unmark foo Remove single mark from whichever view has it 21 | // [criteria] unmark Remove all marks from matched view 22 | // [criteria] unmark foo Remove single mark from matched view 23 | 24 | struct cmd_results *cmd_unmark(int argc, char **argv) { 25 | // Determine the container 26 | struct sway_container *con = NULL; 27 | if (config->handler_context.node_overridden) { 28 | con = config->handler_context.container; 29 | } 30 | 31 | // Determine the mark 32 | char *mark = NULL; 33 | if (argc > 0) { 34 | mark = join_args(argv, argc); 35 | } 36 | 37 | if (con && mark) { 38 | // Remove the mark from the given container 39 | if (container_has_mark(con, mark)) { 40 | container_find_and_unmark(mark); 41 | } 42 | } else if (con && !mark) { 43 | // Clear all marks from the given container 44 | remove_mark(con); 45 | } else if (!con && mark) { 46 | // Remove mark from whichever container has it 47 | container_find_and_unmark(mark); 48 | } else { 49 | // Remove all marks from all containers 50 | root_for_each_container(remove_all_marks_iterator, NULL); 51 | } 52 | free(mark); 53 | 54 | return cmd_results_new(CMD_SUCCESS, NULL); 55 | } 56 | -------------------------------------------------------------------------------- /sway/commands/urgent.c: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "sway/commands.h" 3 | #include "sway/config.h" 4 | #include "sway/tree/arrange.h" 5 | #include "sway/tree/container.h" 6 | #include "sway/tree/view.h" 7 | #include "util.h" 8 | 9 | struct cmd_results *cmd_urgent(int argc, char **argv) { 10 | struct cmd_results *error = NULL; 11 | if ((error = checkarg(argc, "urgent", EXPECTED_EQUAL_TO, 1))) { 12 | return error; 13 | } 14 | struct sway_container *container = config->handler_context.container; 15 | if (!container) { 16 | return cmd_results_new(CMD_FAILURE, "No current container"); 17 | } 18 | if (!container->view) { 19 | return cmd_results_new(CMD_INVALID, "Only views can be urgent"); 20 | } 21 | struct sway_view *view = container->view; 22 | 23 | if (strcmp(argv[0], "allow") == 0) { 24 | view->allow_request_urgent = true; 25 | } else if (strcmp(argv[0], "deny") == 0) { 26 | view->allow_request_urgent = false; 27 | } else { 28 | view_set_urgent(view, parse_boolean(argv[0], view_is_urgent(view))); 29 | } 30 | 31 | return cmd_results_new(CMD_SUCCESS, NULL); 32 | } 33 | -------------------------------------------------------------------------------- /sway/commands/workspace_layout.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | 5 | struct cmd_results *cmd_workspace_layout(int argc, char **argv) { 6 | struct cmd_results *error = NULL; 7 | if ((error = checkarg(argc, "workspace_layout", EXPECTED_EQUAL_TO, 1))) { 8 | return error; 9 | } 10 | if (strcasecmp(argv[0], "default") == 0) { 11 | config->default_layout = L_NONE; 12 | } else if (strcasecmp(argv[0], "stacking") == 0) { 13 | config->default_layout = L_STACKED; 14 | } else if (strcasecmp(argv[0], "tabbed") == 0) { 15 | config->default_layout = L_TABBED; 16 | } else { 17 | return cmd_results_new(CMD_INVALID, 18 | "Expected 'workspace_layout '"); 19 | } 20 | return cmd_results_new(CMD_SUCCESS, NULL); 21 | } 22 | -------------------------------------------------------------------------------- /sway/commands/ws_auto_back_and_forth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/commands.h" 4 | #include "util.h" 5 | 6 | struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) { 7 | struct cmd_results *error = NULL; 8 | if ((error = checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1))) { 9 | return error; 10 | } 11 | config->auto_back_and_forth = 12 | parse_boolean(argv[0], config->auto_back_and_forth); 13 | return cmd_results_new(CMD_SUCCESS, NULL); 14 | } 15 | -------------------------------------------------------------------------------- /sway/commands/xwayland.c: -------------------------------------------------------------------------------- 1 | #include "sway/config.h" 2 | #include "log.h" 3 | #include "sway/commands.h" 4 | #include "sway/server.h" 5 | #include "util.h" 6 | 7 | struct cmd_results *cmd_xwayland(int argc, char **argv) { 8 | struct cmd_results *error = NULL; 9 | if ((error = checkarg(argc, "xwayland", EXPECTED_EQUAL_TO, 1))) { 10 | return error; 11 | } 12 | 13 | #ifdef WLR_HAS_XWAYLAND 14 | enum xwayland_mode xwayland; 15 | if (strcmp(argv[0], "force") == 0) { 16 | xwayland = XWAYLAND_MODE_IMMEDIATE; 17 | } else if (parse_boolean(argv[0], true)) { 18 | xwayland = XWAYLAND_MODE_LAZY; 19 | } else { 20 | xwayland = XWAYLAND_MODE_DISABLED; 21 | } 22 | 23 | // config->xwayland is reset to the previous value on reload in 24 | // load_main_config() 25 | if (config->reloading && config->xwayland != xwayland) { 26 | return cmd_results_new(CMD_FAILURE, 27 | "xwayland can only be enabled/disabled at launch"); 28 | } 29 | config->xwayland = xwayland; 30 | #else 31 | sway_log(SWAY_INFO, "Ignoring `xwayland` command, " 32 | "sway hasn't been built with Xwayland support"); 33 | #endif 34 | 35 | return cmd_results_new(CMD_SUCCESS, NULL); 36 | } 37 | -------------------------------------------------------------------------------- /sway/realtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "sway/server.h" 6 | #include "log.h" 7 | 8 | static void child_fork_callback(void) { 9 | struct sched_param param; 10 | 11 | param.sched_priority = 0; 12 | 13 | int ret = pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m); 14 | if (ret != 0) { 15 | sway_log(SWAY_ERROR, "Failed to reset scheduler policy on fork"); 16 | } 17 | } 18 | 19 | void set_rr_scheduling(void) { 20 | int prio = sched_get_priority_min(SCHED_RR); 21 | int old_policy; 22 | int ret; 23 | struct sched_param param; 24 | 25 | ret = pthread_getschedparam(pthread_self(), &old_policy, ¶m); 26 | if (ret != 0) { 27 | sway_log(SWAY_DEBUG, "Failed to get old scheduling priority"); 28 | return; 29 | } 30 | 31 | param.sched_priority = prio; 32 | 33 | ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); 34 | if (ret != 0) { 35 | sway_log(SWAY_INFO, "Failed to set scheduling priority to %d", prio); 36 | return; 37 | } 38 | 39 | pthread_atfork(NULL, NULL, child_fork_callback); 40 | } 41 | -------------------------------------------------------------------------------- /sway/xdg_activation_v1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sway/desktop/launcher.h" 4 | #include "sway/tree/view.h" 5 | #include "sway/tree/workspace.h" 6 | 7 | void xdg_activation_v1_handle_request_activate(struct wl_listener *listener, 8 | void *data) { 9 | const struct wlr_xdg_activation_v1_request_activate_event *event = data; 10 | 11 | struct wlr_xdg_surface *xdg_surface = 12 | wlr_xdg_surface_try_from_wlr_surface(event->surface); 13 | if (xdg_surface == NULL) { 14 | return; 15 | } 16 | struct sway_view *view = xdg_surface->data; 17 | if (view == NULL) { 18 | return; 19 | } 20 | 21 | struct launcher_ctx *ctx = event->token->data; 22 | if (ctx == NULL) { 23 | return; 24 | } 25 | 26 | if (!xdg_surface->surface->mapped) { 27 | // This is a startup notification. If we are tracking it, the data 28 | // field is a launcher_ctx. 29 | if (ctx->activated) { 30 | // This ctx has already been activated and cannot be used again 31 | // for a startup notification. It will be destroyed 32 | return; 33 | } else { 34 | ctx->activated = true; 35 | view_assign_ctx(view, ctx); 36 | } 37 | return; 38 | } 39 | 40 | // This is an activation request. If this context is internal we have ctx->seat. 41 | if (ctx->seat) { 42 | view_request_activate(view, ctx->seat); 43 | return; 44 | } 45 | 46 | // Otherwise, activate if passed from another focused client 47 | if (ctx->token->seat && ctx->had_focused_surface) { 48 | view_request_activate(view, ctx->token->seat->data); 49 | } else { 50 | // The token is valid, but cannot be used to activate a window 51 | view_request_urgent(view); 52 | } 53 | } 54 | 55 | void xdg_activation_v1_handle_new_token(struct wl_listener *listener, void *data) { 56 | struct wlr_xdg_activation_token_v1 *token = data; 57 | struct sway_seat *seat = token->seat ? token->seat->data : 58 | input_manager_current_seat(); 59 | 60 | struct sway_workspace *ws = seat_get_focused_workspace(seat); 61 | if (ws) { 62 | launcher_ctx_create(token, &ws->node); 63 | return; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /swaybar/meson.build: -------------------------------------------------------------------------------- 1 | tray_files = have_tray ? [ 2 | 'tray/host.c', 3 | 'tray/icon.c', 4 | 'tray/item.c', 5 | 'tray/tray.c', 6 | 'tray/watcher.c' 7 | ] : [] 8 | 9 | swaybar_deps = [ 10 | cairo, 11 | gdk_pixbuf, 12 | jsonc, 13 | math, 14 | pango, 15 | pangocairo, 16 | rt, 17 | wayland_client, 18 | wayland_cursor 19 | ] 20 | if have_tray 21 | swaybar_deps += sdbus 22 | endif 23 | 24 | executable( 25 | 'swaybar', [ 26 | 'bar.c', 27 | 'config.c', 28 | 'i3bar.c', 29 | 'image.c', 30 | 'input.c', 31 | 'ipc.c', 32 | 'main.c', 33 | 'render.c', 34 | 'status_line.c', 35 | tray_files, 36 | wl_protos_src, 37 | ], 38 | include_directories: [sway_inc], 39 | dependencies: swaybar_deps, 40 | link_with: [lib_sway_common, lib_sway_client], 41 | install: true 42 | ) 43 | -------------------------------------------------------------------------------- /swaymsg/meson.build: -------------------------------------------------------------------------------- 1 | executable( 2 | 'swaymsg', 3 | 'main.c', 4 | include_directories: [sway_inc], 5 | dependencies: [jsonc], 6 | link_with: [lib_sway_common], 7 | install: true 8 | ) 9 | -------------------------------------------------------------------------------- /swaynag/meson.build: -------------------------------------------------------------------------------- 1 | executable( 2 | 'swaynag', [ 3 | 'config.c', 4 | 'main.c', 5 | 'render.c', 6 | 'swaynag.c', 7 | 'types.c', 8 | wl_protos_src, 9 | ], 10 | include_directories: [sway_inc], 11 | dependencies: [ 12 | cairo, 13 | pango, 14 | pangocairo, 15 | rt, 16 | wayland_client, 17 | wayland_cursor, 18 | ], 19 | link_with: [lib_sway_common, lib_sway_client], 20 | install: true 21 | ) 22 | --------------------------------------------------------------------------------