aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ISSUE_TEMPLATE.md34
-rw-r--r--README.ja.md22
-rw-r--r--README.md23
-rw-r--r--common/util.c68
-rw-r--r--completions/fish/swayidle.fish3
-rw-r--r--completions/fish/swaylock.fish38
-rw-r--r--completions/fish/swaymsg.fish17
-rw-r--r--completions/fish/swaynag.fish29
-rw-r--r--include/sway/output.h4
-rw-r--r--include/sway/tree/container.h51
-rw-r--r--include/sway/tree/view.h44
-rw-r--r--include/util.h20
-rw-r--r--meson.build2
-rw-r--r--sway/commands/border.c60
-rw-r--r--sway/commands/client.c4
-rw-r--r--sway/commands/focus.c109
-rw-r--r--sway/commands/mark.c19
-rw-r--r--sway/commands/move.c76
-rw-r--r--sway/commands/reload.c4
-rw-r--r--sway/commands/show_marks.c4
-rw-r--r--sway/commands/swap.c4
-rw-r--r--sway/commands/unmark.c41
-rw-r--r--sway/criteria.c5
-rw-r--r--sway/desktop/output.c17
-rw-r--r--sway/desktop/render.c30
-rw-r--r--sway/desktop/transaction.c16
-rw-r--r--sway/input/cursor.c15
-rw-r--r--sway/input/input-manager.c1
-rw-r--r--sway/input/seat.c6
-rw-r--r--sway/ipc-json.c38
-rw-r--r--sway/ipc-server.c8
-rw-r--r--sway/main.c29
-rw-r--r--sway/tree/container.c170
-rw-r--r--sway/tree/output.c22
-rw-r--r--sway/tree/view.c216
-rw-r--r--sway/tree/workspace.c10
-rw-r--r--swayidle/main.c214
-rw-r--r--swayidle/swayidle.1.scd14
-rw-r--r--swaylock/swaylock.1.scd26
-rw-r--r--swaymsg/main.c13
40 files changed, 800 insertions, 726 deletions
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md
new file mode 100644
index 00000000..5f3bb6bb
--- /dev/null
+++ b/ISSUE_TEMPLATE.md
@@ -0,0 +1,34 @@
+If you are using the nvidia proprietary driver for any reason, you have two choices:
+
+1. Uninstall it and use nouveau instead
+2. Use X11+i3 and close your browser tab
+
+If `lsmod | grep nvidia | wc -l` shows anything other than zero, your bug report is not welcome here.
+
+Otherwise, please include the following four components in your bug report: sway version, debug log, configuration (if applicable), and an explanation of steps taken to reproduce the issue.
+
+Obtain your version like so:
+
+ swaymsg -t get_version
+
+If this doesn't work, use:
+
+ sway -v
+
+* Sway Version:
+
+Obtain a debug log like so:
+
+ sway -d 2> ~/sway.log
+
+This will record information about sway's activity when it's running. Briefly reproduce your problem and exit sway. When preparing a debug log, brevity is important - start up sway, do the minimum work necessary to reproduce the error, then close sway.
+
+Upload the debug log to a pastebin service such as [gist.github.com](https://gist.github.com), and link to it below.
+
+* Debug Log:
+
+You should try to reproduce the issue with the default configuration. If you cannot, please reproduce with a minimal configuration, upload the config to a pastebin service, and link to it below.
+
+* Configuration File:
+
+Finally, explain the steps you took in plain English to reproduce the problem below.
diff --git a/README.ja.md b/README.ja.md
index ae2301fb..b9e541f0 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -29,24 +29,22 @@ Swayは沢山のディストリビューションで提供されています。"
次の依存パッケージをインストールしてください:
-* meson
-* [wlc](https://github.com/Cloudef/wlc)
+* meson \*
+* [wlroots](https://github.com/swaywm/wlroots)
* wayland
-* xwayland
-* libinput >= 1.6.0
-* libcap
+* wayland-protocols \*
* pcre
-* json-c >= 0.13
+* json-c
* pango
* cairo
-* gdk-pixbuf2 *
-* pam **
-* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (manで必要です)
-* git
+* gdk-pixbuf2 \*\*
+* pam (オプション: swaylockとPAMで必要)
+* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (manで必要です) \*
+* git \*
-_\*swaybar,swaybg,swaylockでのみ必要です_
+_\*コンパイルの時_
-_\*\*swaylockでのみ必要です_
+_\*\*オプション: swaybgとswaylockでのみ必要です_
次のコマンドを実行してください:
diff --git a/README.md b/README.md
index ca47b876..6cb212fc 100644
--- a/README.md
+++ b/README.md
@@ -32,27 +32,22 @@ channel or shoot an email to sir@cmpwn.com for advice.
Install dependencies:
-* meson
+* meson \*
* [wlroots](https://github.com/swaywm/wlroots)
* wayland
-* xwayland
-* libinput >= 1.6.0
-* libcap
+* wayland-protocols \*
* pcre
-* json-c >= 0.13
+* json-c
* pango
* cairo
-* gdk-pixbuf2 *
-* pam **
-* dbus >= 1.10 ***
-* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (required for man pages)
-* git
+* gdk-pixbuf2 \*\*
+* pam (optional: PAM support for swaylock)
+* [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (optional: man pages) \*
+* git \*
-_\*Only required for swaybar, swaybg, and swaylock_
+_\*Compile-time dep_
-_\*\*Only required for swaylock_
-
-_\*\*\*Only required for tray support_
+_\*\*optional: required for swaybg and swaylock_
Run these commands:
diff --git a/common/util.c b/common/util.c
index 561b3804..f4588b57 100644
--- a/common/util.c
+++ b/common/util.c
@@ -1,4 +1,5 @@
#define _XOPEN_SOURCE 700
+#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -139,60 +140,17 @@ bool parse_boolean(const char *boolean, bool current) {
return false;
}
-char* resolve_path(const char* path) {
- struct stat sb;
- ssize_t r;
- int i;
- char *current = NULL;
- char *resolved = NULL;
-
- if(!(current = strdup(path))) {
- return NULL;
- }
- for (i = 0; i < 16; ++i) {
- if (lstat(current, &sb) == -1) {
- goto failed;
- }
- if((sb.st_mode & S_IFMT) != S_IFLNK) {
- return current;
- }
- if (!(resolved = malloc(sb.st_size + 1))) {
- goto failed;
- }
- r = readlink(current, resolved, sb.st_size);
- if (r == -1 || r > sb.st_size) {
- goto failed;
- }
- resolved[r] = '\0';
- free(current);
- current = strdup(resolved);
- free(resolved);
- resolved = NULL;
+enum wlr_direction opposite_direction(enum wlr_direction d) {
+ switch (d) {
+ case WLR_DIRECTION_UP:
+ return WLR_DIRECTION_DOWN;
+ case WLR_DIRECTION_DOWN:
+ return WLR_DIRECTION_UP;
+ case WLR_DIRECTION_RIGHT:
+ return WLR_DIRECTION_LEFT;
+ case WLR_DIRECTION_LEFT:
+ return WLR_DIRECTION_RIGHT;
}
-
-failed:
- free(resolved);
- free(current);
- return NULL;
-}
-
-bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) {
- switch (dir) {
- case MOVE_UP:
- *out = WLR_DIRECTION_UP;
- break;
- case MOVE_DOWN:
- *out = WLR_DIRECTION_DOWN;
- break;
- case MOVE_LEFT:
- *out = WLR_DIRECTION_LEFT;
- break;
- case MOVE_RIGHT:
- *out = WLR_DIRECTION_RIGHT;
- break;
- default:
- return false;
- }
-
- return true;
+ assert(false);
+ return 0;
}
diff --git a/completions/fish/swayidle.fish b/completions/fish/swayidle.fish
new file mode 100644
index 00000000..71279925
--- /dev/null
+++ b/completions/fish/swayidle.fish
@@ -0,0 +1,3 @@
+# swayidle
+complete -c swayidle -s h --description 'show help'
+complete -c swayidle -s d --description 'debug'
diff --git a/completions/fish/swaylock.fish b/completions/fish/swaylock.fish
index 965a22d2..99dff48f 100644
--- a/completions/fish/swaylock.fish
+++ b/completions/fish/swaylock.fish
@@ -1,11 +1,39 @@
# swaylock(1) completion
+complete -c swaylock -s C -l config --description 'The config file to use. Default: $HOME/.swaylock/config, $XDG_CONFIG_HOME/swaylock/config, and SYSCONFDIR/swaylock/config.'
complete -c swaylock -s h -l help --description "Show help message and quit."
-complete -c swaylock -s c -l color --description "Turn the screen into the given color. If -i is used, this sets the background of the image into the given color. Defaults to white (ffffff), or transparent (00000000) if an image is in use."
complete -c swaylock -s f -l daemonize --description "Fork into the background after spawning. Note: this is the default bahavior of i3lock."
+complete -c swaylock -s v -l version --description "Show the version number and quit."
+complete -c swaylock -s s -l socket --description "Use the specified socket path. Otherwise, swaymsg will as sway where the socket is (which is the value of $SWAYSOCK, then of $I350CK)."
+complete -c swaylock -s e -l ignore-empty-password --description 'When an empty password is provided by the user, do not validate it.'
+
+# Appearance
+complete -c swaylock -s u -l no-unlock-indicator --description "Disable the unlock indicator."
complete -c swaylock -s i -l image --description "Display the given image, optionally on the given output. Use -c to set a background color."
-complete -c swaylock -l scaling --description "Scaling mode for images: stretch, fill, fit, center, or tile."
+complete -c swaylock -s s -l scaling --description "Scaling mode for images: stretch, fill, fit, center, or tile."
complete -c swaylock -s t -l tiling --description "Same as --scaling=tile."
-complete -c swaylock -s u -l no-unlock-indicator --description "Disable the unlock indicator."
-complete -c swaylock -s v -l version --description "Show the version number and quit."
-complete -c swaylock -l socket --description "Use the specified socket path. Othherwise, swaymsg will as sway where the socket is (which is the value of $SWAYSOCK, then of $I350CK)."
+complete -c swaylock -s c -l color --description "Turn the screen into the given color. If -i is used, this sets the background of the image into the given color. Defaults to white (ffffff), or transparent (00000000) if an image is in use."
+complete -c swaylock -l bs-hl-color --description 'Sets the color of backspace highlight segments.'
+complete -c swaylock -l font --description 'Sets the font of the text inside the indicator.'
+complete -c swaylock -l indicator-radius --description 'Sets the radius of the indicator to radius pixels. Default: 50'
+complete -c swaylock -l indicator-thickness --description 'Sets the thickness of the indicator to thickness pixels. Default: 10'
+complete -c swaylock -l inside-color --description 'Sets the color of the inside of the indicator when typing or idle.'
+complete -c swaylock -l inside-clear-color --description 'Sets the color of the inside of the indicator when cleared.'
+complete -c swaylock -l inside-ver-color --description 'Sets the color of the inside of the indicator when verifying.'
+complete -c swaylock -l inside-wrong-color --description 'Sets the color of the inside of the indicator when invalid.'
+complete -c swaylock -l key-hl-color --description 'Sets the color of key press highlight segments.'
+complete -c swaylock -l line-color --description 'Sets the color of the lines that separate the inside and outside of the indicator when typing or idle.'
+complete -c swaylock -l line-clear-color --description 'Sets the color of the lines that separate the inside and outside of the indicator when cleared.'
+complete -c swaylock -l line-ver-color --description 'Sets the color of the lines that separate the inside and outside of the indicator when verifying.'
+complete -c swaylock -l line-wrong-color --description 'Sets the color of the lines that separate the inside and outside of the indicator when invalid.'
+complete -c swaylock -s n -l line-uses-inside --description 'Use the color of the inside of the indicator for the line separating the inside and outside of the indicator.'
+complete -c swaylock -s r -l line-uses-ring --description 'Use the outer ring\'s color for the line separating the inside and outside of the indicator.'
+complete -c swaylock -l ring-color --description 'Sets the color of the outside of the indicator when typing or idle.'
+complete -c swaylock -l ring-clear-color --description 'Sets the color of the outside of the indicator when cleared.'
+complete -c swaylock -l ring-ver-color --description 'Sets the color of the outside of the indicator when verifying.'
+complete -c swaylock -l ring-wrong-color --description 'Sets the color of the outside of the indicator when invalid.'
+complete -c swaylock -l separator-color --description 'Sets the color of the lines that separate highlight segments.'
+complete -c swaylock -l text-color --description 'Sets the color of the text inside the indicator when typing or idle.'
+complete -c swaylock -l text-clear-color --description 'Sets the color of the text inside the indicator when cleared.'
+complete -c swaylock -l text-ver-color --description 'Sets the color of the text inside the indicator when verifying.'
+complete -c swaylock -l text-wrong-color --description 'Sets the color of the text inside the indicator when invalid.'
diff --git a/completions/fish/swaymsg.fish b/completions/fish/swaymsg.fish
index e798db77..1e5bf3da 100644
--- a/completions/fish/swaymsg.fish
+++ b/completions/fish/swaymsg.fish
@@ -2,7 +2,18 @@
complete -c swaymsg -s h -l help --description "Show help message and quit."
complete -c swaymsg -s q -l quiet --description "Sends the IPC message but does not print the response from sway."
-complete -c swaymsg -s r -l raw --description "Use raw output even if using tty."
-complete -c swaymsg -s s -l socket --description "Use the specified socket path. Otherwise, swaymsg will ask where the socket is (which is the value of $SWAYSOCK, then of $I3SOCK)."
-complete -c swaymsg -s t -l type --description "Specify the type of IPC message."
complete -c swaymsg -s v -l version --description "Print the version (of swaymsg) and quit."
+complete -c swaymsg -s r -l raw --description "Use raw output even if using tty."
+complete -c swaymsg -s s -l socket -r --description "Use the specified socket path. Otherwise, swaymsg will ask where the socket is (which is the value of $SWAYSOCK, then of $I3SOCK)."
+
+complete -c swaymsg -s t -l type -fr --description "Specify the type of IPC message."
+complete -c swaymsg -s t -l type -fra 'get_workspaces' --description "Gets a JSON-encoded list of workspaces and their status."
+complete -c swaymsg -s t -l type -fra 'get_inputs' --description "Gets a JSON-encoded list of current inputs."
+complete -c swaymsg -s t -l type -fra 'get_outputs' --description "Gets a JSON-encoded list of current outputs."
+complete -c swaymsg -s t -l type -fra 'get_tree' --description "Gets a JSON-encoded layout tree of all open windows, containers, outputs, workspaces, and so on."
+complete -c swaymsg -s t -l type -fra 'get_marks' --description "Get a JSON-encoded list of marks."
+complete -c swaymsg -s t -l type -fra 'get_bar_config' --description "Get a JSON-encoded configuration for swaybar."
+complete -c swaymsg -s t -l type -fra 'get_version' --description "Get JSON-encoded version information for the running instance of sway."
+complete -c swaymsg -s t -l type -fra 'get_binding_modes' --description "Gets a JSON-encoded list of currently configured binding modes."
+complete -c swaymsg -s t -l type -fra 'get_config' --description "Gets a JSON-encoded copy of the current configuration."
+complete -c swaymsg -s t -l type -fra 'send_tick' --description "Sends a tick event to all subscribed clients."
diff --git a/completions/fish/swaynag.fish b/completions/fish/swaynag.fish
new file mode 100644
index 00000000..784d7fad
--- /dev/null
+++ b/completions/fish/swaynag.fish
@@ -0,0 +1,29 @@
+# swaynag
+complete -c swaynag -s C -l config --description 'The config file to use. Default: $HOME/.swaylock/config, $XDG_CONFIG_HOME/swaylock/config, and SYSCONFDIR/swaylock/config.'
+complete -c swaynag -s d -l debug --description 'Enable debugging.'
+complete -c swaynag -s e -l edge --description 'Set the edge to use: top or bottom'
+complete -c swaynag -s f -l font --description 'Set the font to use.'
+complete -c swaynag -s h -l help --description 'Show help message and quit.'
+complete -c swaynag -s b -l button --description 'Create a button with a text and an action which is executed when pressed. Multiple buttons can be defined by providing the flag multiple times.'
+complete -c swaynag -s l -l detailed-message --description 'Read a detailed message from stdin. A button to toggle details will be added. Details are shown in a scrollable multi-line text area.'
+complete -c swaynag -s L -l detailed-button --description 'Set the text for the button that toggles details. This has no effect if there is not a detailed message. The default is "Toggle details".'
+complete -c swaynag -s m -l message --description 'Set the message text.'
+complete -c swaynag -s o -l output --description 'Set the output to use.'
+complete -c swaynag -s s -l dismiss-button --description 'Sets the text for the dismiss nagbar button. The default is "X".'
+complete -c swaynag -s t -l type --description 'Set the message type. Two types are created by default "error" and "warning". Custom types can be defined in the config file.'
+complete -c swaynag -s v -l version --description 'Show the version number and quit.'
+
+# Appearance
+complete -c swaynag -l background --description 'Set the color of the background.'
+complete -c swaynag -l border --description 'Set the color of the border.'
+complete -c swaynag -l border-bottom --description 'Set the color of the bottom border.'
+complete -c swaynag -l button-background --description 'Set the color for the background for buttons.'
+complete -c swaynag -l text --description 'Set the text color.'
+complete -c swaynag -l border-bottom-size --description 'Set the thickness of the bottom border.'
+complete -c swaynag -l message-padding --description 'Set the padding for the message.'
+complete -c swaynag -l details-border-size --description 'Set the thickness for the details border.'
+complete -c swaynag -l button-border-size --description 'Set the thickness for the button border.'
+complete -c swaynag -l button-gap --description 'Set the size of the gap between buttons.'
+complete -c swaynag -l button-dismiss-gap --description 'Set the size of the gap between the dismiss button and another button.'
+complete -c swaynag -l button-margin-right --description 'Set the margin from the right of the dismiss button to edge.'
+complete -c swaynag -l button-padding --description 'Set the padding for the button text.'
diff --git a/include/sway/output.h b/include/sway/output.h
index 369e62ce..5efe1660 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -62,7 +62,7 @@ void output_begin_destroy(struct sway_output *output);
struct sway_output *output_from_wlr_output(struct wlr_output *output);
struct sway_output *output_get_in_direction(struct sway_output *reference,
- enum movement_direction direction);
+ enum wlr_direction direction);
void output_add_workspace(struct sway_output *output,
struct sway_workspace *workspace);
@@ -86,6 +86,8 @@ void output_damage_whole_container(struct sway_output *output,
struct sway_output *output_by_name(const char *name);
+struct sway_output *output_by_identifier(const char *identifier);
+
void output_sort_workspaces(struct sway_output *output);
struct output_config *output_find_config(struct sway_output *output);
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 920ef038..4366a010 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -36,7 +36,6 @@ struct sway_output;
struct sway_workspace;
struct sway_view;
-enum movement_direction;
enum wlr_direction;
struct sway_container_state {
@@ -54,16 +53,16 @@ struct sway_container_state {
struct sway_container *focused_inactive_child;
bool focused;
- // View properties
- double view_x, view_y;
- double view_width, view_height;
-
enum sway_container_border border;
int border_thickness;
bool border_top;
bool border_bottom;
bool border_left;
bool border_right;
+
+ // View properties
+ double view_x, view_y;
+ double view_width, view_height;
};
struct sway_container {
@@ -92,6 +91,18 @@ struct sway_container {
bool is_fullscreen;
+ enum sway_container_border border;
+
+ // Used when the view changes to CSD unexpectedly. This will be a non-B_CSD
+ // border which we use to restore when the view returns to SSD.
+ enum sway_container_border saved_border;
+
+ int border_thickness;
+ bool border_top;
+ bool border_bottom;
+ bool border_left;
+ bool border_right;
+
// The gaps currently applied to the container.
double current_gaps;
@@ -116,6 +127,12 @@ struct sway_container {
size_t title_height;
size_t title_baseline;
+ list_t *marks; // char *
+ struct wlr_texture *marks_focused;
+ struct wlr_texture *marks_focused_inactive;
+ struct wlr_texture *marks_unfocused;
+ struct wlr_texture *marks_urgent;
+
struct {
struct wl_signal destroy;
} events;
@@ -287,12 +304,32 @@ void container_detach(struct sway_container *child);
void container_replace(struct sway_container *container,
struct sway_container *replacement);
-bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out);
-
struct sway_container *container_split(struct sway_container *child,
enum sway_container_layout layout);
bool container_is_transient_for(struct sway_container *child,
struct sway_container *ancestor);
+/**
+ * Find any container that has the given mark and return it.
+ */
+struct sway_container *container_find_mark(char *mark);
+
+/**
+ * Find any container that has the given mark and remove the mark from the
+ * container. Returns true if it matched a container.
+ */
+bool container_find_and_unmark(char *mark);
+
+/**
+ * Remove all marks from the container.
+ */
+void container_clear_marks(struct sway_container *container);
+
+bool container_has_mark(struct sway_container *container, char *mark);
+
+void container_add_mark(struct sway_container *container, char *mark);
+
+void container_update_marks_textures(struct sway_container *container);
+
#endif
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 0240f294..4a8c3cb1 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -80,24 +80,8 @@ struct sway_view {
char *title_format;
- // Our border types are B_NONE, B_PIXEL, B_NORMAL and B_CSD. We normally
- // just assign this to the border property and ignore the other two.
- // However, when a view using CSD is tiled, we want to render our own
- // borders as well. So in this case the border property becomes one of the
- // first three, and using_csd is true.
- // Lastly, views can change their decoration mode at any time. When an SSD
- // view becomes CSD without our approval, we save the SSD border type so it
- // can be restored if/when the view returns from CSD to SSD.
- enum sway_container_border border;
- enum sway_container_border saved_border;
bool using_csd;
- int border_thickness;
- bool border_top;
- bool border_bottom;
- bool border_left;
- bool border_right;
-
struct timespec urgent;
bool allow_request_urgent;
struct wl_event_source *urgent_timer;
@@ -116,12 +100,6 @@ struct sway_view {
bool destroying;
list_t *executed_criteria; // struct criteria *
- list_t *marks; // char *
-
- struct wlr_texture *marks_focused;
- struct wlr_texture *marks_focused_inactive;
- struct wlr_texture *marks_unfocused;
- struct wlr_texture *marks_urgent;
union {
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
@@ -369,28 +347,6 @@ void view_update_title(struct sway_view *view, bool force);
void view_execute_criteria(struct sway_view *view);
/**
- * Find any view that has the given mark and return it.
- */
-struct sway_view *view_find_mark(char *mark);
-
-/**
- * Find any view that has the given mark and remove the mark from the view.
- * Returns true if it matched a view.
- */
-bool view_find_and_unmark(char *mark);
-
-/**
- * Remove all marks from the view.
- */
-void view_clear_marks(struct sway_view *view);
-
-bool view_has_mark(struct sway_view *view, char *mark);
-
-void view_add_mark(struct sway_view *view, char *mark);
-
-void view_update_marks_textures(struct sway_view *view);
-
-/**
* Returns true if there's a possibility the view may be rendered on screen.
* Intended for damage tracking.
*/
diff --git a/include/util.h b/include/util.h
index 19d2e7cf..f143d0c0 100644
--- a/include/util.h
+++ b/include/util.h
@@ -7,15 +7,6 @@
#include <wlr/types/wlr_output_layout.h>
#include <xkbcommon/xkbcommon.h>
-enum movement_direction {
- MOVE_LEFT,
- MOVE_RIGHT,
- MOVE_UP,
- MOVE_DOWN,
- MOVE_PARENT,
- MOVE_CHILD,
-};
-
/**
* Wrap i into the range [0, max[
*/
@@ -68,15 +59,6 @@ uint32_t parse_color(const char *color);
*/
bool parse_boolean(const char *boolean, bool current);
-/**
- * Given a path string, recurseively resolves any symlinks to their targets
- * (which may be a file, directory) and returns the result.
- * argument is returned. Caller must free the returned buffer.
- * If an error occures, if the path does not exist or if the path corresponds
- * to a dangling symlink, NULL is returned.
- */
-char* resolve_path(const char* path);
-
-bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out);
+enum wlr_direction opposite_direction(enum wlr_direction d);
#endif
diff --git a/meson.build b/meson.build
index 1e2b53fa..6b23b4e3 100644
--- a/meson.build
+++ b/meson.build
@@ -244,8 +244,10 @@ endif
if (get_option('fish-completions'))
fish_files = files(
'completions/fish/sway.fish',
+ 'completions/fish/swayidle.fish',
'completions/fish/swaylock.fish',
'completions/fish/swaymsg.fish',
+ 'completions/fish/swaynag.fish',
)
fish_install_dir = datadir + '/fish/completions'
diff --git a/sway/commands/border.c b/sway/commands/border.c
index 37047812..b6eab550 100644
--- a/sway/commands/border.c
+++ b/sway/commands/border.c
@@ -12,37 +12,41 @@
// in use (we set using_csd instead and render a sway border).
// - view->saved_border should be the last applied border when switching to CSD.
// - view->using_csd should always reflect whether CSD is applied or not.
-static void set_border(struct sway_view *view,
+static void set_border(struct sway_container *con,
enum sway_container_border new_border) {
- if (view->using_csd && new_border != B_CSD) {
- view_set_csd_from_server(view, false);
- } else if (!view->using_csd && new_border == B_CSD) {
- view_set_csd_from_server(view, true);
- view->saved_border = view->border;
+ if (con->view) {
+ if (con->view->using_csd && new_border != B_CSD) {
+ view_set_csd_from_server(con->view, false);
+ } else if (!con->view->using_csd && new_border == B_CSD) {
+ view_set_csd_from_server(con->view, true);
+ con->saved_border = con->border;
+ }
+ }
+ if (new_border != B_CSD || container_is_floating(con)) {
+ con->border = new_border;
}
- if (new_border != B_CSD || container_is_floating(view->container)) {
- view->border = new_border;
+ if (con->view) {
+ con->view->using_csd = new_border == B_CSD;
}
- view->using_csd = new_border == B_CSD;
}
-static void border_toggle(struct sway_view *view) {
- if (view->using_csd) {
- set_border(view, B_NONE);
+static void border_toggle(struct sway_container *con) {
+ if (con->view && con->view->using_csd) {
+ set_border(con, B_NONE);
return;
}
- switch (view->border) {
+ switch (con->border) {
case B_NONE:
- set_border(view, B_PIXEL);
+ set_border(con, B_PIXEL);
break;
case B_PIXEL:
- set_border(view, B_NORMAL);
+ set_border(con, B_NORMAL);
break;
case B_NORMAL:
- if (view->xdg_decoration) {
- set_border(view, B_CSD);
+ if (con->view && con->view->xdg_decoration) {
+ set_border(con, B_CSD);
} else {
- set_border(view, B_NONE);
+ set_border(con, B_NONE);
}
break;
case B_CSD:
@@ -66,33 +70,33 @@ struct cmd_results *cmd_border(int argc, char **argv) {
struct sway_view *view = container->view;
if (strcmp(argv[0], "none") == 0) {
- set_border(view, B_NONE);
+ set_border(container, B_NONE);
} else if (strcmp(argv[0], "normal") == 0) {
- set_border(view, B_NORMAL);
+ set_border(container, B_NORMAL);
} else if (strcmp(argv[0], "pixel") == 0) {
- set_border(view, B_PIXEL);
+ set_border(container, B_PIXEL);
} else if (strcmp(argv[0], "csd") == 0) {
- if (!view->xdg_decoration) {
+ if (!view || !view->xdg_decoration) {
return cmd_results_new(CMD_INVALID, "border",
"This window doesn't support client side decorations");
}
- set_border(view, B_CSD);
+ set_border(container, B_CSD);
} else if (strcmp(argv[0], "toggle") == 0) {
- border_toggle(view);
+ border_toggle(container);
} else {
return cmd_results_new(CMD_INVALID, "border",
"Expected 'border <none|normal|pixel|csd|toggle>' "
"or 'border pixel <px>'");
}
if (argc == 2) {
- view->border_thickness = atoi(argv[1]);
+ container->border_thickness = atoi(argv[1]);
}
- if (container_is_floating(view->container)) {
- container_set_geometry_from_floating_view(view->container);
+ if (container_is_floating(container)) {
+ container_set_geometry_from_floating_view(container);
}
- arrange_container(view->container);
+ arrange_container(container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/client.c b/sway/commands/client.c
index 9f54fa94..746e8713 100644
--- a/sway/commands/client.c
+++ b/sway/commands/client.c
@@ -5,9 +5,7 @@
#include "sway/tree/container.h"
static void rebuild_textures_iterator(struct sway_container *con, void *data) {
- if (con->view) {
- view_update_marks_textures(con->view);
- }
+ container_update_marks_textures(con);
container_update_title_textures(con);
}
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 2204f722..cef92144 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -1,4 +1,5 @@
#include <strings.h>
+#include <wlr/types/wlr_output_layout.h>
#include <wlr/util/log.h>
#include "log.h"
#include "sway/commands.h"
@@ -13,20 +14,16 @@
#include "stringop.h"
#include "util.h"
-static bool parse_movement_direction(const char *name,
- enum movement_direction *out) {
+static bool parse_direction(const char *name,
+ enum wlr_direction *out) {
if (strcasecmp(name, "left") == 0) {
- *out = MOVE_LEFT;
+ *out = WLR_DIRECTION_LEFT;
} else if (strcasecmp(name, "right") == 0) {
- *out = MOVE_RIGHT;
+ *out = WLR_DIRECTION_RIGHT;
} else if (strcasecmp(name, "up") == 0) {
- *out = MOVE_UP;
+ *out = WLR_DIRECTION_UP;
} else if (strcasecmp(name, "down") == 0) {
- *out = MOVE_DOWN;
- } else if (strcasecmp(name, "parent") == 0) {
- *out = MOVE_PARENT;
- } else if (strcasecmp(name, "child") == 0) {
- *out = MOVE_CHILD;
+ *out = WLR_DIRECTION_DOWN;
} else {
return false;
}
@@ -38,7 +35,7 @@ static bool parse_movement_direction(const char *name,
* Get node in the direction of newly entered output.
*/
static struct sway_node *get_node_in_output_direction(
- struct sway_output *output, enum movement_direction dir) {
+ struct sway_output *output, enum wlr_direction dir) {
struct sway_seat *seat = config->handler_context.seat;
struct sway_workspace *ws = output_get_active_workspace(output);
if (ws->fullscreen) {
@@ -48,7 +45,7 @@ static struct sway_node *get_node_in_output_direction(
if (ws->tiling->length > 0) {
switch (dir) {
- case MOVE_LEFT:
+ case WLR_DIRECTION_LEFT:
if (ws->layout == L_HORIZ || ws->layout == L_TABBED) {
// get most right child of new output
container = ws->tiling->items[ws->tiling->length-1];
@@ -56,7 +53,7 @@ static struct sway_node *get_node_in_output_direction(
container = seat_get_focus_inactive_tiling(seat, ws);
}
break;
- case MOVE_RIGHT:
+ case WLR_DIRECTION_RIGHT:
if (ws->layout == L_HORIZ || ws->layout == L_TABBED) {
// get most left child of new output
container = ws->tiling->items[0];
@@ -64,7 +61,7 @@ static struct sway_node *get_node_in_output_direction(
container = seat_get_focus_inactive_tiling(seat, ws);
}
break;
- case MOVE_UP:
+ case WLR_DIRECTION_UP:
if (ws->layout == L_VERT || ws->layout == L_STACKED) {
// get most bottom child of new output
container = ws->tiling->items[ws->tiling->length-1];
@@ -72,7 +69,7 @@ static struct sway_node *get_node_in_output_direction(
container = seat_get_focus_inactive_tiling(seat, ws);
}
break;
- case MOVE_DOWN: {
+ case WLR_DIRECTION_DOWN:
if (ws->layout == L_VERT || ws->layout == L_STACKED) {
// get most top child of new output
container = ws->tiling->items[0];
@@ -81,9 +78,6 @@ static struct sway_node *get_node_in_output_direction(
}
break;
}
- default:
- break;
- }
}
if (container) {
@@ -95,11 +89,8 @@ static struct sway_node *get_node_in_output_direction(
}
static struct sway_node *node_get_in_direction(struct sway_container *container,
- struct sway_seat *seat, enum movement_direction dir) {
+ struct sway_seat *seat, enum wlr_direction dir) {
if (container->is_fullscreen) {
- if (dir == MOVE_PARENT) {
- return NULL;
- }
// Fullscreen container with a direction - go straight to outputs
struct sway_output *output = container->workspace->output;
struct sway_output *new_output = output_get_in_direction(output, dir);
@@ -108,9 +99,6 @@ static struct sway_node *node_get_in_direction(struct sway_container *container,
}
return get_node_in_output_direction(new_output, dir);
}
- if (dir == MOVE_PARENT) {
- return node_get_parent(&container->node);
- }
struct sway_container *wrap_candidate = NULL;
struct sway_container *current = container;
@@ -122,15 +110,15 @@ static struct sway_node *node_get_in_direction(struct sway_container *container,
container_parent_layout(current);
list_t *siblings = container_get_siblings(current);
- if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
+ if (dir == WLR_DIRECTION_LEFT || dir == WLR_DIRECTION_RIGHT) {
if (parent_layout == L_HORIZ || parent_layout == L_TABBED) {
can_move = true;
- desired = idx + (dir == MOVE_LEFT ? -1 : 1);
+ desired = idx + (dir == WLR_DIRECTION_LEFT ? -1 : 1);
}
} else {
if (parent_layout == L_VERT || parent_layout == L_STACKED) {
can_move = true;
- desired = idx + (dir == MOVE_UP ? -1 : 1);
+ desired = idx + (dir == WLR_DIRECTION_UP ? -1 : 1);
}
}
@@ -200,15 +188,25 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
struct sway_output *output = output_by_name(identifier);
if (!output) {
- enum movement_direction direction;
- if (!parse_movement_direction(identifier, &direction) ||
- direction == MOVE_PARENT || direction == MOVE_CHILD) {
+ enum wlr_direction direction;
+ if (!parse_direction(identifier, &direction)) {
free(identifier);
return cmd_results_new(CMD_INVALID, "focus",
"There is no output with that name");
}
struct sway_workspace *ws = seat_get_focused_workspace(seat);
output = output_get_in_direction(ws->output, direction);
+
+ if (!output) {
+ int center_lx = ws->output->lx + ws->output->width / 2;
+ int center_ly = ws->output->ly + ws->output->height / 2;
+ struct wlr_output *target = wlr_output_layout_farthest_output(
+ root->output_layout, opposite_direction(direction),
+ ws->output->wlr_output, center_lx, center_ly);
+ if (target) {
+ output = output_from_wlr_output(target);
+ }
+ }
}
free(identifier);
@@ -220,6 +218,31 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
+static struct cmd_results *focus_parent(void) {
+ struct sway_seat *seat = config->handler_context.seat;
+ struct sway_container *con = config->handler_context.container;
+ if (!con || con->is_fullscreen) {
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ }
+ struct sway_node *parent = node_get_parent(&con->node);
+ if (parent) {
+ seat_set_focus(seat, parent);
+ seat_consider_warp_to_focus(seat);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+static struct cmd_results *focus_child(void) {
+ struct sway_seat *seat = config->handler_context.seat;
+ struct sway_node *node = config->handler_context.node;
+ struct sway_node *focus = seat_get_active_tiling_child(seat, node);
+ if (focus) {
+ seat_set_focus(seat, focus);
+ seat_consider_warp_to_focus(seat);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
struct cmd_results *cmd_focus(int argc, char **argv) {
if (config->reading || !config->active) {
return cmd_results_new(CMD_DEFER, NULL, NULL);
@@ -257,27 +280,21 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
return focus_output(seat, argc, argv);
}
- enum movement_direction direction = 0;
- if (!parse_movement_direction(argv[0], &direction)) {
+ if (strcasecmp(argv[0], "parent") == 0) {
+ return focus_parent();
+ }
+ if (strcasecmp(argv[0], "child") == 0) {
+ return focus_child();
+ }
+
+ enum wlr_direction direction = 0;
+ if (!parse_direction(argv[0], &direction)) {
return cmd_results_new(CMD_INVALID, "focus",
"Expected 'focus <direction|parent|child|mode_toggle|floating|tiling>' "
"or 'focus output <direction|name>'");
}
- if (direction == MOVE_CHILD) {
- struct sway_node *focus = seat_get_active_tiling_child(seat, node);
- if (focus) {
- seat_set_focus(seat, focus);
- seat_consider_warp_to_focus(seat);
- }
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
- }
-
if (node->type == N_WORKSPACE) {
- if (direction == MOVE_PARENT) {
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
- }
-
// Jump to the next output
struct sway_output *new_output =
output_get_in_direction(workspace->output, direction);
diff --git a/sway/commands/mark.c b/sway/commands/mark.c
index b1f47be1..c76e1d63 100644
--- a/sway/commands/mark.c
+++ b/sway/commands/mark.c
@@ -19,11 +19,10 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
return error;
}
struct sway_container *container = config->handler_context.container;
- if (!container || !container->view) {
+ if (!container) {
return cmd_results_new(CMD_INVALID, "mark",
- "Only views can have marks");
+ "Only containers can have marks");
}
- struct sway_view *view = container->view;
bool add = false, toggle = false;
while (argc > 0 && strncmp(*argv, "--", 2) == 0) {
@@ -47,22 +46,24 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
}
char *mark = join_args(argv, argc);
- bool had_mark = view_has_mark(view, mark);
+ bool had_mark = container_has_mark(container, mark);
if (!add) {
// Replacing
- view_clear_marks(view);
+ container_clear_marks(container);
}
- view_find_and_unmark(mark);
+ container_find_and_unmark(mark);
if (!toggle || !had_mark) {
- view_add_mark(view, mark);
+ container_add_mark(container, mark);
}
free(mark);
- view_update_marks_textures(view);
- view_execute_criteria(view);
+ container_update_marks_textures(container);
+ if (container->view) {
+ view_execute_criteria(container->view);
+ }
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/move.c b/sway/commands/move.c
index ffe12d41..7d8c1f1a 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -27,19 +27,6 @@ static const char *expected_syntax =
"'move <container|window|workspace> [to] output <name|direction>' or "
"'move <container|window> [to] mark <mark>'";
-enum wlr_direction opposite_direction(enum wlr_direction d) {
- switch (d) {
- case WLR_DIRECTION_UP:
- return WLR_DIRECTION_DOWN;
- case WLR_DIRECTION_DOWN:
- return WLR_DIRECTION_UP;
- case WLR_DIRECTION_RIGHT:
- return WLR_DIRECTION_LEFT;
- default:
- return WLR_DIRECTION_RIGHT;
- }
-}
-
static struct sway_output *output_in_direction(const char *direction_string,
struct sway_output *reference, int ref_lx, int ref_ly) {
struct {
@@ -81,14 +68,14 @@ static struct sway_output *output_in_direction(const char *direction_string,
}
static bool is_parallel(enum sway_container_layout layout,
- enum movement_direction dir) {
+ enum wlr_direction dir) {
switch (layout) {
case L_TABBED:
case L_HORIZ:
- return dir == MOVE_LEFT || dir == MOVE_RIGHT;
+ return dir == WLR_DIRECTION_LEFT || dir == WLR_DIRECTION_RIGHT;
case L_STACKED:
case L_VERT:
- return dir == MOVE_UP || dir == MOVE_DOWN;
+ return dir == WLR_DIRECTION_UP || dir == WLR_DIRECTION_DOWN;
default:
return false;
}
@@ -115,7 +102,7 @@ static void workspace_focus_fullscreen(struct sway_workspace *workspace) {
static void container_move_to_container_from_direction(
struct sway_container *container, struct sway_container *destination,
- enum movement_direction move_dir) {
+ enum wlr_direction move_dir) {
if (destination->view) {
if (destination->parent == container->parent &&
destination->workspace == container->workspace) {
@@ -126,7 +113,8 @@ static void container_move_to_container_from_direction(
list_swap(siblings, container_index, destination_index);
} else {
wlr_log(WLR_DEBUG, "Promoting to sibling of cousin");
- int offset = move_dir == MOVE_LEFT || move_dir == MOVE_UP;
+ int offset =
+ move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP;
int index = container_sibling_index(destination) + offset;
if (destination->parent) {
container_insert_child(destination->parent, container, index);
@@ -141,7 +129,8 @@ static void container_move_to_container_from_direction(
if (is_parallel(destination->layout, move_dir)) {
wlr_log(WLR_DEBUG, "Reparenting container (parallel)");
- int index = move_dir == MOVE_RIGHT || move_dir == MOVE_DOWN ?
+ int index =
+ move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ?
0 : destination->children->length;
container_insert_child(destination, container, index);
container->width = container->height = 0;
@@ -164,10 +153,11 @@ static void container_move_to_container_from_direction(
static void container_move_to_workspace_from_direction(
struct sway_container *container, struct sway_workspace *workspace,
- enum movement_direction move_dir) {
+ enum wlr_direction move_dir) {
if (is_parallel(workspace->layout, move_dir)) {
wlr_log(WLR_DEBUG, "Reparenting container (parallel)");
- int index = move_dir == MOVE_RIGHT || move_dir == MOVE_DOWN ?
+ int index =
+ move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ?
0 : workspace->tiling->length;
workspace_insert_tiling(workspace, container, index);
return;
@@ -258,28 +248,31 @@ static void container_move_to_container(struct sway_container *container,
* container, switches the layout of the workspace, and drops the child back in.
* In other words, rejigger it. */
static void workspace_rejigger(struct sway_workspace *ws,
- struct sway_container *child, enum movement_direction move_dir) {
+ struct sway_container *child, enum wlr_direction move_dir) {
if (!child->parent && ws->tiling->length == 1) {
ws->layout =
- move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
+ move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_RIGHT ?
+ L_HORIZ : L_VERT;
workspace_update_representation(ws);
return;
}
container_detach(child);
struct sway_container *new_parent = workspace_wrap_children(ws);
- int index = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? 0 : 1;
+ int index =
+ move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP ? 0 : 1;
workspace_insert_tiling(ws, child, index);
container_flatten(new_parent);
ws->layout =
- move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
+ move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_RIGHT ?
+ L_HORIZ : L_VERT;
workspace_update_representation(ws);
child->width = child->height = 0;
}
// Returns true if moved
static bool container_move_in_direction(struct sway_container *container,
- enum movement_direction move_dir) {
+ enum wlr_direction move_dir) {
// If moving a fullscreen view, only consider outputs
if (container->is_fullscreen) {
struct sway_output *new_output =
@@ -305,7 +298,8 @@ static bool container_move_in_direction(struct sway_container *container,
// The below loop stops once we hit the workspace because current->parent
// is NULL for the topmost containers in a workspace.
struct sway_container *current = container;
- int offs = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? -1 : 1;
+ int offs =
+ move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP ? -1 : 1;
while (current) {
list_t *siblings = container_get_siblings(current);
@@ -494,12 +488,12 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
}
destination = seat_get_focus_inactive(seat, &new_output->node);
} else if (strcasecmp(argv[1], "mark") == 0) {
- struct sway_view *dest_view = view_find_mark(argv[2]);
- if (dest_view == NULL) {
+ struct sway_container *dest_con = container_find_mark(argv[2]);
+ if (dest_con == NULL) {
return cmd_results_new(CMD_FAILURE, "move",
"Mark '%s' not found", argv[2]);
}
- destination = &dest_view->container->node;
+ destination = &dest_con->node;
} else {
return cmd_results_new(CMD_INVALID, "move", expected_syntax);
}
@@ -642,7 +636,7 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {
}
static struct cmd_results *cmd_move_in_direction(
- enum movement_direction direction, int argc, char **argv) {
+ enum wlr_direction direction, int argc, char **argv) {
int move_amt = 10;
if (argc > 1) {
char *inv;
@@ -666,22 +660,18 @@ static struct cmd_results *cmd_move_in_direction(
double lx = container->x;
double ly = container->y;
switch (direction) {
- case MOVE_LEFT:
+ case WLR_DIRECTION_LEFT:
lx -= move_amt;
break;
- case MOVE_RIGHT:
+ case WLR_DIRECTION_RIGHT:
lx += move_amt;
break;
- case MOVE_UP:
+ case WLR_DIRECTION_UP:
ly -= move_amt;
break;
- case MOVE_DOWN:
+ case WLR_DIRECTION_DOWN:
ly += move_amt;
break;
- case MOVE_PARENT:
- case MOVE_CHILD:
- return cmd_results_new(CMD_FAILURE, "move",
- "Cannot move floating container to parent or child");
}
container_floating_move_to(container, lx, ly);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
@@ -850,13 +840,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
}
if (strcasecmp(argv[0], "left") == 0) {
- return cmd_move_in_direction(MOVE_LEFT, argc, argv);
+ return cmd_move_in_direction(WLR_DIRECTION_LEFT, argc, argv);
} else if (strcasecmp(argv[0], "right") == 0) {
- return cmd_move_in_direction(MOVE_RIGHT, argc, argv);
+ return cmd_move_in_direction(WLR_DIRECTION_RIGHT, argc, argv);
} else if (strcasecmp(argv[0], "up") == 0) {
- return cmd_move_in_direction(MOVE_UP, argc, argv);
+ return cmd_move_in_direction(WLR_DIRECTION_UP, argc, argv);
} else if (strcasecmp(argv[0], "down") == 0) {
- return cmd_move_in_direction(MOVE_DOWN, argc, argv);
+ return cmd_move_in_direction(WLR_DIRECTION_DOWN, argc, argv);
} else if ((strcasecmp(argv[0], "container") == 0
|| strcasecmp(argv[0], "window") == 0) ||
(strcasecmp(argv[0], "--no-auto-back-and-forth") && argc >= 2
diff --git a/sway/commands/reload.c b/sway/commands/reload.c
index 791081a8..62105cdc 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -10,9 +10,7 @@
#include "log.h"
static void rebuild_textures_iterator(struct sway_container *con, void *data) {
- if (con->view) {
- view_update_marks_textures(con->view);
- }
+ container_update_marks_textures(con);
container_update_title_textures(con);
}
diff --git a/sway/commands/show_marks.c b/sway/commands/show_marks.c
index d501584a..0baf6852 100644
--- a/sway/commands/show_marks.c
+++ b/sway/commands/show_marks.c
@@ -11,9 +11,7 @@
#include "util.h"
static void rebuild_marks_iterator(struct sway_container *con, void *data) {
- if (con->view) {
- view_update_marks_textures(con->view);
- }
+ container_update_marks_textures(con);
}
struct cmd_results *cmd_show_marks(int argc, char **argv) {
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index a70a6cdd..23e8d583 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -159,8 +159,8 @@ static bool test_id(struct sway_container *container, void *id) {
}
static bool test_mark(struct sway_container *container, void *mark) {
- if (container->view && container->view->marks->length) {
- return !list_seq_find(container->view->marks,
+ if (container->marks->length) {
+ return !list_seq_find(container->marks,
(int (*)(const void *, const void *))strcmp, mark);
}
return false;
diff --git a/sway/commands/unmark.c b/sway/commands/unmark.c
index c671ed4e..98ac6ff2 100644
--- a/sway/commands/unmark.c
+++ b/sway/commands/unmark.c
@@ -9,10 +9,8 @@
#include "stringop.h"
static void remove_all_marks_iterator(struct sway_container *con, void *data) {
- if (con->view) {
- view_clear_marks(con->view);
- view_update_marks_textures(con->view);
- }
+ container_clear_marks(con);
+ container_update_marks_textures(con);
}
// unmark Remove all marks from all views
@@ -21,15 +19,10 @@ static void remove_all_marks_iterator(struct sway_container *con, void *data) {
// [criteria] unmark foo Remove single mark from matched view
struct cmd_results *cmd_unmark(int argc, char **argv) {
- // Determine the view
- struct sway_view *view = NULL;
+ // Determine the container
+ struct sway_container *con = NULL;
if (config->handler_context.using_criteria) {
- struct sway_container *container = config->handler_context.container;
- if (!container || !container->view) {
- return cmd_results_new(CMD_INVALID, "unmark",
- "Only views can have marks");
- }
- view = container->view;
+ con = config->handler_context.container;
}
// Determine the mark
@@ -38,20 +31,20 @@ struct cmd_results *cmd_unmark(int argc, char **argv) {
mark = join_args(argv, argc);
}
- if (view && mark) {
- // Remove the mark from the given view
- if (view_has_mark(view, mark)) {
- view_find_and_unmark(mark);
+ if (con && mark) {
+ // Remove the mark from the given container
+ if (container_has_mark(con, mark)) {
+ container_find_and_unmark(mark);
}
- } else if (view && !mark) {
- // Clear all marks from the given view
- view_clear_marks(view);
- view_update_marks_textures(view);
- } else if (!view && mark) {
- // Remove mark from whichever view has it
- view_find_and_unmark(mark);
+ } else if (con && !mark) {
+ // Clear all marks from the given container
+ container_clear_marks(con);
+ container_update_marks_textures(con);
+ } else if (!con && mark) {
+ // Remove mark from whichever container has it
+ container_find_and_unmark(mark);
} else {
- // Remove all marks from all views
+ // Remove all marks from all containers
root_for_each_container(remove_all_marks_iterator, NULL);
}
free(mark);
diff --git a/sway/criteria.c b/sway/criteria.c
index 89630d90..2f9992e9 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -121,8 +121,9 @@ static bool criteria_matches_view(struct criteria *criteria,
if (criteria->con_mark) {
bool exists = false;
- for (int i = 0; i < view->marks->length; ++i) {
- if (regex_cmp(view->marks->items[i], criteria->con_mark) == 0) {
+ struct sway_container *con = view->container;
+ for (int i = 0; i < con->marks->length; ++i) {
+ if (regex_cmp(con->marks->items[i], criteria->con_mark) == 0) {
exists = true;
break;
}
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index ed9300bb..2b90f151 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -39,6 +39,19 @@ struct sway_output *output_by_name(const char *name) {
return NULL;
}
+struct sway_output *output_by_identifier(const char *identifier) {
+ for (int i = 0; i < root->outputs->length; ++i) {
+ struct sway_output *output = root->outputs->items[i];
+ char output_identifier[128];
+ snprintf(output_identifier, sizeof(output_identifier), "%s %s %s", output->wlr_output->make,
+ output->wlr_output->model, output->wlr_output->serial);
+ if (strcasecmp(output_identifier, identifier) == 0) {
+ return output;
+ }
+ }
+ return NULL;
+}
+
/**
* Rotate a child's position relative to a parent. The parent size is (pw, ph),
* the child position is (*sx, *sy) and its size is (sw, sh).
@@ -519,9 +532,7 @@ static void handle_transform(struct wl_listener *listener, void *data) {
static void update_textures(struct sway_container *con, void *data) {
container_update_title_textures(con);
- if (con->view) {
- view_update_marks_textures(con->view);
- }
+ container_update_marks_textures(con);
}
static void handle_scale(struct wl_listener *listener, void *data) {
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 1a72f752..cf6da682 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -625,19 +625,19 @@ static void render_containers_linear(struct sway_output *output,
if (view_is_urgent(view)) {
colors = &config->border_colors.urgent;
title_texture = child->title_urgent;
- marks_texture = view->marks_urgent;
+ marks_texture = child->marks_urgent;
} else if (state->focused || parent->focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
- marks_texture = view->marks_focused;
+ marks_texture = child->marks_focused;
} else if (child == parent->active_child) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
- marks_texture = view->marks_focused_inactive;
+ marks_texture = child->marks_focused_inactive;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
- marks_texture = view->marks_unfocused;
+ marks_texture = child->marks_unfocused;
}
if (state->border == B_NORMAL) {
@@ -681,19 +681,19 @@ static void render_containers_tabbed(struct sway_output *output,
if (urgent) {
colors = &config->border_colors.urgent;
title_texture = child->title_urgent;
- marks_texture = view ? view->marks_urgent : NULL;
+ marks_texture = child->marks_urgent;
} else if (cstate->focused || parent->focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
- marks_texture = view ? view->marks_focused : NULL;
+ marks_texture = child->marks_focused;
} else if (child == parent->active_child) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
- marks_texture = view ? view->marks_focused_inactive : NULL;
+ marks_texture = child->marks_focused_inactive;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
- marks_texture = view ? view->marks_unfocused : NULL;
+ marks_texture = child->marks_unfocused;
}
int x = cstate->con_x + tab_width * i;
@@ -746,19 +746,19 @@ static void render_containers_stacked(struct sway_output *output,
if (urgent) {
colors = &config->border_colors.urgent;
title_texture = child->title_urgent;
- marks_texture = view ? view->marks_urgent : NULL;
+ marks_texture = child->marks_urgent;
} else if (cstate->focused || parent->focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
- marks_texture = view ? view->marks_focused : NULL;
+ marks_texture = child->marks_focused;
} else if (child == parent->active_child) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
- marks_texture = view ? view->marks_focused_inactive : NULL;
+ marks_texture = child->marks_focused_inactive;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
- marks_texture = view ? view->marks_unfocused : NULL;
+ marks_texture = child->marks_unfocused;
}
int y = parent->box.y + titlebar_height * i;
@@ -841,15 +841,15 @@ static void render_floating_container(struct sway_output *soutput,
if (view_is_urgent(view)) {
colors = &config->border_colors.urgent;
title_texture = con->title_urgent;
- marks_texture = view->marks_urgent;
+ marks_texture = con->marks_urgent;
} else if (con->current.focused) {
colors = &config->border_colors.focused;
title_texture = con->title_focused;
- marks_texture = view->marks_focused;
+ marks_texture = con->marks_focused;
} else {
colors = &config->border_colors.unfocused;
title_texture = con->title_unfocused;
- marks_texture = view->marks_unfocused;
+ marks_texture = con->marks_unfocused;
}
if (con->current.border == B_NORMAL) {
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
index 955b05d6..44156d41 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -137,6 +137,12 @@ static void copy_container_state(struct sway_container *container,
state->is_fullscreen = container->is_fullscreen;
state->parent = container->parent;
state->workspace = container->workspace;
+ state->border = container->border;
+ state->border_thickness = container->border_thickness;
+ state->border_top = container->border_top;
+ state->border_left = container->border_left;
+ state->border_right = container->border_right;
+ state->border_bottom = container->border_bottom;
if (container->view) {
struct sway_view *view = container->view;
@@ -144,12 +150,6 @@ static void copy_container_state(struct sway_container *container,
state->view_y = view->y;
state->view_width = view->width;
state->view_height = view->height;
- state->border = view->border;
- state->border_thickness = view->border_thickness;
- state->border_top = view->border_top;
- state->border_left = view->border_left;
- state->border_right = view->border_right;
- state->border_bottom = view->border_bottom;
} else {
state->children = create_list();
list_cat(state->children, container->children);
@@ -301,7 +301,9 @@ static void transaction_apply(struct sway_transaction *transaction) {
if (root->outputs->length) {
struct sway_seat *seat;
wl_list_for_each(seat, &server.input->seats, link) {
- cursor_rebase(seat->cursor);
+ if (seat->operation == OP_NONE) {
+ cursor_rebase(seat->cursor);
+ }
}
}
}
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 3942b64f..c539df40 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -187,23 +187,22 @@ static enum wlr_edges find_edge(struct sway_container *cont,
if (!cont->view) {
return WLR_EDGE_NONE;
}
- struct sway_view *view = cont->view;
- if (view->border == B_NONE || !view->border_thickness ||
- view->border == B_CSD) {
+ if (cont->border == B_NONE || !cont->border_thickness ||
+ cont->border == B_CSD) {
return WLR_EDGE_NONE;
}
enum wlr_edges edge = 0;
- if (cursor->cursor->x < cont->x + view->border_thickness) {
+ if (cursor->cursor->x < cont->x + cont->border_thickness) {
edge |= WLR_EDGE_LEFT;
}
- if (cursor->cursor->y < cont->y + view->border_thickness) {
+ if (cursor->cursor->y < cont->y + cont->border_thickness) {
edge |= WLR_EDGE_TOP;
}
- if (cursor->cursor->x >= cont->x + cont->width - view->border_thickness) {
+ if (cursor->cursor->x >= cont->x + cont->width - cont->border_thickness) {
edge |= WLR_EDGE_RIGHT;
}
- if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) {
+ if (cursor->cursor->y >= cont->y + cont->height - cont->border_thickness) {
edge |= WLR_EDGE_BOTTOM;
}
@@ -585,7 +584,7 @@ static void cursor_do_rebase(struct sway_cursor *cursor, uint32_t time_msec,
void cursor_rebase(struct sway_cursor *cursor) {
uint32_t time_msec = get_current_time_msec();
- struct wlr_surface *surface;
+ struct wlr_surface *surface = NULL;
double sx, sy;
cursor->previous.node = node_at_coords(cursor->seat,
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index 91c45dd1..68445d68 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -431,6 +431,7 @@ void input_manager_set_focus(struct sway_node *node) {
struct sway_seat *seat;
wl_list_for_each(seat, &server.input->seats, link) {
seat_set_focus(seat, node);
+ seat_consider_warp_to_focus(seat);
}
}
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 577619a7..64419afa 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -185,7 +185,11 @@ static void handle_seat_node_destroy(struct wl_listener *listener, void *data) {
seat_set_focus(seat, next_focus);
} else {
// Setting focus_inactive
+ focus = seat_get_focus_inactive(seat, &root->node);
seat_set_raw_focus(seat, next_focus);
+ if (focus->type == N_CONTAINER) {
+ seat_set_raw_focus(seat, &focus->sway_container->workspace->node);
+ }
seat_set_raw_focus(seat, focus);
}
}
@@ -944,7 +948,7 @@ struct sway_node *seat_get_focus(struct sway_seat *seat) {
if (!seat->has_focus) {
return NULL;
}
- if (wl_list_length(&seat->focus_stack) == 0) {
+ if (wl_list_empty(&seat->focus_stack)) {
return NULL;
}
struct sway_seat_node *current =
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 2cd0cb2d..7cc965c8 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -136,13 +136,18 @@ static void ipc_json_describe_output(struct sway_output *output,
json_object_new_int(mode->width));
json_object_object_add(mode_object, "height",
json_object_new_int(mode->height));
- json_object_object_add(mode_object, "refresh",
- json_object_new_int(mode->refresh));
json_object_array_add(modes_array, mode_object);
}
json_object_object_add(object, "modes", modes_array);
+ json_object *current_mode_object = json_object_new_object();
+ json_object_object_add(current_mode_object, "width",
+ json_object_new_int(wlr_output->width));
+ json_object_object_add(current_mode_object, "height",
+ json_object_new_int(wlr_output->height));
+ json_object_object_add(object, "current_mode", current_mode_object);
+
struct sway_node *parent = node_get_parent(&output->node);
struct wlr_box parent_box = {0, 0, 0, 0};
@@ -229,14 +234,10 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
json_object_object_add(object, "app_id",
app_id ? json_object_new_string(app_id) : NULL);
- const char *class = view_get_class(c->view);
- json_object_object_add(object, "class",
- class ? json_object_new_string(class) : NULL);
-
json_object *marks = json_object_new_array();
- list_t *view_marks = c->view->marks;
- for (int i = 0; i < view_marks->length; ++i) {
- json_object_array_add(marks, json_object_new_string(view_marks->items[i]));
+ list_t *con_marks = c->marks;
+ for (int i = 0; i < con_marks->length; ++i) {
+ json_object_array_add(marks, json_object_new_string(con_marks->items[i]));
}
json_object_object_add(object, "marks", marks);
@@ -269,13 +270,17 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
json_object *window_props = json_object_new_object();
- json_object_object_add(window_props, "class",
- class ? json_object_new_string(class) : NULL);
+ const char *class = view_get_class(c->view);
+ if (class) {
+ json_object_object_add(window_props, "class", json_object_new_string(class));
+ }
const char *instance = view_get_instance(c->view);
- json_object_object_add(window_props, "instance",
- instance ? json_object_new_string(instance) : NULL);
- json_object_object_add(window_props, "title",
- c->title ? json_object_new_string(c->title) : NULL);
+ if (instance) {
+ json_object_object_add(window_props, "instance", json_object_new_string(instance));
+ }
+ if (c->title) {
+ json_object_object_add(window_props, "title", json_object_new_string(c->title));
+ }
// the transient_for key is always present in i3's output
uint32_t parent_id = view_get_x11_parent_id(c->view);
@@ -284,8 +289,7 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
const char *role = view_get_window_role(c->view);
if (role) {
- json_object_object_add(window_props, "window_role",
- json_object_new_string(role));
+ json_object_object_add(window_props, "window_role", json_object_new_string(role));
}
json_object_object_add(object, "window_properties", window_props);
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 21f431be..6466d263 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -563,11 +563,9 @@ static void ipc_get_workspaces_callback(struct sway_workspace *workspace,
static void ipc_get_marks_callback(struct sway_container *con, void *data) {
json_object *marks = (json_object *)data;
- if (con->view && con->view->marks) {
- for (int i = 0; i < con->view->marks->length; ++i) {
- char *mark = (char *)con->view->marks->items[i];
- json_object_array_add(marks, json_object_new_string(mark));
- }
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *mark = (char *)con->marks->items[i];
+ json_object_array_add(marks, json_object_new_string(mark));
}
}
diff --git a/sway/main.c b/sway/main.c
index cc5f7187..920cea11 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -29,7 +29,7 @@
static bool terminate_request = false;
static int exit_value = 0;
-struct sway_server server;
+struct sway_server server = {0};
void sway_terminate(int exit_code) {
terminate_request = true;
@@ -194,21 +194,23 @@ static void log_kernel(void) {
}
-static void drop_permissions(void) {
+static bool drop_permissions(void) {
if (getuid() != geteuid() || getgid() != getegid()) {
if (setgid(getgid()) != 0) {
- wlr_log(WLR_ERROR, "Unable to drop root");
- exit(EXIT_FAILURE);
+ wlr_log(WLR_ERROR, "Unable to drop root, refusing to start");
+ return false;
}
if (setuid(getuid()) != 0) {
- wlr_log(WLR_ERROR, "Unable to drop root");
- exit(EXIT_FAILURE);
+ wlr_log(WLR_ERROR, "Unable to drop root, refusing to start");
+ return false;
}
}
if (setuid(0) != -1) {
- wlr_log(WLR_ERROR, "Root privileges can be restored.");
- exit(EXIT_FAILURE);
+ wlr_log(WLR_ERROR, "Unable to drop root (we shouldn't be able to "
+ "restore it after setuid), refusing to start");
+ return false;
}
+ return true;
}
void enable_debug_flag(const char *flag) {
@@ -317,11 +319,13 @@ int main(int argc, char **argv) {
}
if (optind < argc) { // Behave as IPC client
- if(optind != 1) {
+ if (optind != 1) {
wlr_log(WLR_ERROR, "Don't use options with the IPC client");
exit(EXIT_FAILURE);
}
- drop_permissions();
+ if (!drop_permissions()) {
+ exit(EXIT_FAILURE);
+ }
char *socket_path = getenv("SWAYSOCK");
if (!socket_path) {
wlr_log(WLR_ERROR, "Unable to retrieve socket path");
@@ -341,7 +345,10 @@ int main(int argc, char **argv) {
detect_proprietary(allow_unsupported_gpu);
detect_raspi();
- drop_permissions();
+ if (!drop_permissions()) {
+ server_fini(&server);
+ exit(EXIT_FAILURE);
+ }
// handle SIGTERM signals
signal(SIGTERM, sig_handler);
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 58d3df34..458ed7ff 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -39,6 +39,7 @@ struct sway_container *container_create(struct sway_view *view) {
c->children = create_list();
c->current.children = create_list();
}
+ c->marks = create_list();
c->outputs = create_list();
wl_signal_init(&c->events.destroy);
@@ -66,6 +67,13 @@ void container_destroy(struct sway_container *con) {
list_free(con->current.children);
list_free(con->outputs);
+ list_foreach(con->marks, free);
+ list_free(con->marks);
+ wlr_texture_destroy(con->marks_focused);
+ wlr_texture_destroy(con->marks_focused_inactive);
+ wlr_texture_destroy(con->marks_unfocused);
+ wlr_texture_destroy(con->marks_urgent);
+
if (con->view) {
if (con->view->container == con) {
con->view->container = NULL;
@@ -639,8 +647,8 @@ void container_init_floating(struct sway_container *con) {
view->y = ws->y + (ws->height - view->height) / 2;
// If the view's border is B_NONE then these properties are ignored.
- view->border_top = view->border_bottom = true;
- view->border_left = view->border_right = true;
+ con->border_top = con->border_bottom = true;
+ con->border_left = con->border_right = true;
container_set_geometry_from_floating_view(con);
}
@@ -662,7 +670,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
if (container->view) {
view_set_tiled(container->view, false);
if (container->view->using_csd) {
- container->view->border = B_CSD;
+ container->border = B_CSD;
}
}
if (old_parent) {
@@ -676,11 +684,8 @@ void container_set_floating(struct sway_container *container, bool enable) {
container_detach(container);
struct sway_container *reference =
seat_get_focus_inactive_tiling(seat, workspace);
- if (reference && reference->view) {
- reference = reference->parent;
- }
if (reference) {
- container_add_child(reference, container);
+ container_add_sibling(reference, container, 1);
container->width = reference->width;
container->height = reference->height;
} else {
@@ -691,7 +696,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
if (container->view) {
view_set_tiled(container->view, true);
if (container->view->using_csd) {
- container->view->border = container->view->saved_border;
+ container->border = container->saved_border;
}
}
container->is_sticky = false;
@@ -713,9 +718,9 @@ void container_set_geometry_from_floating_view(struct sway_container *con) {
size_t border_width = 0;
size_t top = 0;
- if (view->border != B_CSD) {
- border_width = view->border_thickness * (view->border != B_NONE);
- top = view->border == B_NORMAL ?
+ if (con->border != B_CSD) {
+ border_width = con->border_thickness * (con->border != B_NONE);
+ top = con->border == B_NORMAL ?
container_titlebar_height() : border_width;
}
@@ -999,9 +1004,7 @@ void container_discover_outputs(struct sway_container *con) {
double new_scale = new_output ? new_output->wlr_output->scale : -1;
if (old_scale != new_scale) {
container_update_title_textures(con);
- if (con->view) {
- view_update_marks_textures(con->view);
- }
+ container_update_marks_textures(con);
}
}
@@ -1221,3 +1224,142 @@ bool container_is_transient_for(struct sway_container *child,
child->view && ancestor->view &&
view_is_transient_for(child->view, ancestor->view);
}
+
+static bool find_by_mark_iterator(struct sway_container *con, void *data) {
+ char *mark = data;
+ return container_has_mark(con, mark);
+}
+
+struct sway_container *container_find_mark(char *mark) {
+ return root_find_container(find_by_mark_iterator, mark);
+}
+
+bool container_find_and_unmark(char *mark) {
+ struct sway_container *con = root_find_container(
+ find_by_mark_iterator, mark);
+ if (!con) {
+ return false;
+ }
+
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *con_mark = con->marks->items[i];
+ if (strcmp(con_mark, mark) == 0) {
+ free(con_mark);
+ list_del(con->marks, i);
+ container_update_marks_textures(con);
+ ipc_event_window(con, "mark");
+ return true;
+ }
+ }
+ return false;
+}
+
+void container_clear_marks(struct sway_container *con) {
+ list_foreach(con->marks, free);
+ con->marks->length = 0;
+ ipc_event_window(con, "mark");
+}
+
+bool container_has_mark(struct sway_container *con, char *mark) {
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *item = con->marks->items[i];
+ if (strcmp(item, mark) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void container_add_mark(struct sway_container *con, char *mark) {
+ list_add(con->marks, strdup(mark));
+ ipc_event_window(con, "mark");
+}
+
+static void update_marks_texture(struct sway_container *con,
+ struct wlr_texture **texture, struct border_colors *class) {
+ struct sway_output *output = container_get_effective_output(con);
+ if (!output) {
+ return;
+ }
+ if (*texture) {
+ wlr_texture_destroy(*texture);
+ *texture = NULL;
+ }
+ if (!con->marks->length) {
+ return;
+ }
+
+ size_t len = 0;
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *mark = con->marks->items[i];
+ if (mark[0] != '_') {
+ len += strlen(mark) + 2;
+ }
+ }
+ char *buffer = calloc(len + 1, 1);
+ char *part = malloc(len + 1);
+
+ if (!sway_assert(buffer && part, "Unable to allocate memory")) {
+ free(buffer);
+ return;
+ }
+
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *mark = con->marks->items[i];
+ if (mark[0] != '_') {
+ sprintf(part, "[%s]", mark);
+ strcat(buffer, part);
+ }
+ }
+ free(part);
+
+ double scale = output->wlr_output->scale;
+ int width = 0;
+ int height = con->title_height * scale;
+
+ cairo_t *c = cairo_create(NULL);
+ get_text_size(c, config->font, &width, NULL, NULL, scale, false,
+ "%s", buffer);
+ cairo_destroy(c);
+
+ cairo_surface_t *surface = cairo_image_surface_create(
+ CAIRO_FORMAT_ARGB32, width, height);
+ cairo_t *cairo = cairo_create(surface);
+ cairo_set_source_rgba(cairo, class->background[0], class->background[1],
+ class->background[2], class->background[3]);
+ cairo_paint(cairo);
+ PangoContext *pango = pango_cairo_create_context(cairo);
+ cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST);
+ cairo_set_source_rgba(cairo, class->text[0], class->text[1],
+ class->text[2], class->text[3]);
+ cairo_move_to(cairo, 0, 0);
+
+ pango_printf(cairo, config->font, scale, false, "%s", buffer);
+
+ cairo_surface_flush(surface);
+ unsigned char *data = cairo_image_surface_get_data(surface);
+ int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
+ struct wlr_renderer *renderer = wlr_backend_get_renderer(
+ output->wlr_output->backend);
+ *texture = wlr_texture_from_pixels(
+ renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data);
+ cairo_surface_destroy(surface);
+ g_object_unref(pango);
+ cairo_destroy(cairo);
+ free(buffer);
+}
+
+void container_update_marks_textures(struct sway_container *con) {
+ if (!config->show_marks) {
+ return;
+ }
+ update_marks_texture(con, &con->marks_focused,
+ &config->border_colors.focused);
+ update_marks_texture(con, &con->marks_focused_inactive,
+ &config->border_colors.focused_inactive);
+ update_marks_texture(con, &con->marks_unfocused,
+ &config->border_colors.unfocused);
+ update_marks_texture(con, &con->marks_urgent,
+ &config->border_colors.urgent);
+ container_damage_whole(con);
+}
diff --git a/sway/tree/output.c b/sway/tree/output.c
index e5794b8a..2704920d 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -65,8 +65,13 @@ void output_enable(struct sway_output *output, struct output_config *oc) {
return;
}
struct wlr_output *wlr_output = output->wlr_output;
+ size_t len = sizeof(output->layers) / sizeof(output->layers[0]);
+ for (size_t i = 0; i < len; ++i) {
+ wl_list_init(&output->layers[i]);
+ }
+ wl_signal_init(&output->events.destroy);
+
output->enabled = true;
- apply_output_config(oc, output);
list_add(root->outputs, output);
output->lx = wlr_output->lx;
@@ -92,11 +97,8 @@ void output_enable(struct sway_output *output, struct output_config *oc) {
ipc_event_workspace(NULL, ws, "init");
}
- size_t len = sizeof(output->layers) / sizeof(output->layers[0]);
- for (size_t i = 0; i < len; ++i) {
- wl_list_init(&output->layers[i]);
- }
- wl_signal_init(&output->events.destroy);
+
+ apply_output_config(oc, output);
input_manager_configure_xcursor();
@@ -274,16 +276,14 @@ struct sway_output *output_from_wlr_output(struct wlr_output *output) {
}
struct sway_output *output_get_in_direction(struct sway_output *reference,
- enum movement_direction direction) {
- enum wlr_direction wlr_dir = 0;
- if (!sway_assert(sway_dir_to_wlr(direction, &wlr_dir),
- "got invalid direction: %d", direction)) {
+ enum wlr_direction direction) {
+ if (!sway_assert(direction, "got invalid direction: %d", direction)) {
return NULL;
}
int lx = reference->wlr_output->lx + reference->width / 2;
int ly = reference->wlr_output->ly + reference->height / 2;
struct wlr_output *wlr_adjacent = wlr_output_layout_adjacent_output(
- root->output_layout, wlr_dir, reference->wlr_output, lx, ly);
+ root->output_layout, direction, reference->wlr_output, lx, ly);
if (!wlr_adjacent) {
return NULL;
}
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 4bc9e0f3..1aa59e68 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -35,7 +35,6 @@ void view_init(struct sway_view *view, enum sway_view_type type,
view->type = type;
view->impl = impl;
view->executed_criteria = create_list();
- view->marks = create_list();
view->allow_request_urgent = true;
wl_signal_init(&view->events.unmap);
}
@@ -55,13 +54,6 @@ void view_destroy(struct sway_view *view) {
}
list_free(view->executed_criteria);
- list_foreach(view->marks, free);
- list_free(view->marks);
-
- wlr_texture_destroy(view->marks_focused);
- wlr_texture_destroy(view->marks_focused_inactive);
- wlr_texture_destroy(view->marks_unfocused);
- wlr_texture_destroy(view->marks_urgent);
free(view->title_format);
if (view->impl->destroy) {
@@ -225,21 +217,21 @@ void view_autoconfigure(struct sway_view *view) {
bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS
|| !gaps_to_edge(view);
- view->border_top = view->border_bottom = true;
- view->border_left = view->border_right = true;
+ con->border_top = con->border_bottom = true;
+ con->border_left = con->border_right = true;
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_VERTICAL
|| (smart && !other_views && no_gaps)) {
- view->border_left = con->x - con->current_gaps != ws->x;
+ con->border_left = con->x - con->current_gaps != ws->x;
int right_x = con->x + con->width + con->current_gaps;
- view->border_right = right_x != ws->x + ws->width;
+ con->border_right = right_x != ws->x + ws->width;
}
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_HORIZONTAL
|| (smart && !other_views && no_gaps)) {
- view->border_top = con->y - con->current_gaps != ws->y;
+ con->border_top = con->y - con->current_gaps != ws->y;
int bottom_y = con->y + con->height + con->current_gaps;
- view->border_bottom = bottom_y != ws->y + ws->height;
+ con->border_bottom = bottom_y != ws->y + ws->height;
}
double x, y, width, height;
@@ -252,14 +244,14 @@ void view_autoconfigure(struct sway_view *view) {
enum sway_container_layout layout = container_parent_layout(con);
if (layout == L_TABBED && !container_is_floating(con)) {
y_offset = container_titlebar_height();
- view->border_top = false;
+ con->border_top = false;
} else if (layout == L_STACKED && !container_is_floating(con)) {
list_t *siblings = container_get_siblings(con);
y_offset = container_titlebar_height() * siblings->length;
- view->border_top = false;
+ con->border_top = false;
}
- switch (view->border) {
+ switch (con->border) {
case B_CSD:
case B_NONE:
x = con->x;
@@ -268,29 +260,29 @@ void view_autoconfigure(struct sway_view *view) {
height = con->height - y_offset;
break;
case B_PIXEL:
- x = con->x + view->border_thickness * view->border_left;
- y = con->y + view->border_thickness * view->border_top + y_offset;
+ x = con->x + con->border_thickness * con->border_left;
+ y = con->y + con->border_thickness * con->border_top + y_offset;
width = con->width
- - view->border_thickness * view->border_left
- - view->border_thickness * view->border_right;
+ - con->border_thickness * con->border_left
+ - con->border_thickness * con->border_right;
height = con->height - y_offset
- - view->border_thickness * view->border_top
- - view->border_thickness * view->border_bottom;
+ - con->border_thickness * con->border_top
+ - con->border_thickness * con->border_bottom;
break;
case B_NORMAL:
// Height is: 1px border + 3px pad + title height + 3px pad + 1px border
- x = con->x + view->border_thickness * view->border_left;
+ x = con->x + con->border_thickness * con->border_left;
width = con->width
- - view->border_thickness * view->border_left
- - view->border_thickness * view->border_right;
+ - con->border_thickness * con->border_left
+ - con->border_thickness * con->border_right;
if (y_offset) {
y = con->y + y_offset;
height = con->height - y_offset
- - view->border_thickness * view->border_bottom;
+ - con->border_thickness * con->border_bottom;
} else {
y = con->y + container_titlebar_height();
height = con->height - container_titlebar_height()
- - view->border_thickness * view->border_bottom;
+ - con->border_thickness * con->border_bottom;
}
break;
}
@@ -347,13 +339,14 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled) {
void view_update_csd_from_client(struct sway_view *view, bool enabled) {
wlr_log(WLR_DEBUG, "View %p updated CSD to %i", view, enabled);
- if (enabled && view->border != B_CSD) {
- view->saved_border = view->border;
- if (view->container && container_is_floating(view->container)) {
- view->border = B_CSD;
+ struct sway_container *con = view->container;
+ if (enabled && con && con->border != B_CSD) {
+ con->saved_border = con->border;
+ if (container_is_floating(con)) {
+ con->border = B_CSD;
}
- } else if (!enabled && view->border == B_CSD) {
- view->border = view->saved_border;
+ } else if (!enabled && con && con->border == B_CSD) {
+ con->border = con->saved_border;
}
view->using_csd = enabled;
}
@@ -584,12 +577,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
view->surface_new_subsurface.notify = view_handle_surface_new_subsurface;
if (view->impl->wants_floating && view->impl->wants_floating(view)) {
- view->border = config->floating_border;
- view->border_thickness = config->floating_border_thickness;
+ view->container->border = config->floating_border;
+ view->container->border_thickness = config->floating_border_thickness;
container_set_floating(view->container, true);
} else {
- view->border = config->border;
- view->border_thickness = config->border_thickness;
+ view->container->border = config->border;
+ view->container->border_thickness = config->border_thickness;
view_set_tiled(view, true);
}
@@ -936,153 +929,6 @@ void view_update_title(struct sway_view *view, bool force) {
ipc_event_window(view->container, "title");
}
-static bool find_by_mark_iterator(struct sway_container *con,
- void *data) {
- char *mark = data;
- return con->view && view_has_mark(con->view, mark);
-}
-
-struct sway_view *view_find_mark(char *mark) {
- struct sway_container *container = root_find_container(
- find_by_mark_iterator, mark);
- if (!container) {
- return NULL;
- }
- return container->view;
-}
-
-bool view_find_and_unmark(char *mark) {
- struct sway_container *container = root_find_container(
- find_by_mark_iterator, mark);
- if (!container) {
- return false;
- }
- struct sway_view *view = container->view;
-
- for (int i = 0; i < view->marks->length; ++i) {
- char *view_mark = view->marks->items[i];
- if (strcmp(view_mark, mark) == 0) {
- free(view_mark);
- list_del(view->marks, i);
- view_update_marks_textures(view);
- ipc_event_window(container, "mark");
- return true;
- }
- }
- return false;
-}
-
-void view_clear_marks(struct sway_view *view) {
- list_foreach(view->marks, free);
- view->marks->length = 0;
- ipc_event_window(view->container, "mark");
-}
-
-bool view_has_mark(struct sway_view *view, char *mark) {
- for (int i = 0; i < view->marks->length; ++i) {
- char *item = view->marks->items[i];
- if (strcmp(item, mark) == 0) {
- return true;
- }
- }
- return false;
-}
-
-void view_add_mark(struct sway_view *view, char *mark) {
- list_add(view->marks, strdup(mark));
- ipc_event_window(view->container, "mark");
-}
-
-static void update_marks_texture(struct sway_view *view,
- struct wlr_texture **texture, struct border_colors *class) {
- struct sway_output *output =
- container_get_effective_output(view->container);
- if (!output) {
- return;
- }
- if (*texture) {
- wlr_texture_destroy(*texture);
- *texture = NULL;
- }
- if (!view->marks->length) {
- return;
- }
-
- size_t len = 0;
- for (int i = 0; i < view->marks->length; ++i) {
- char *mark = view->marks->items[i];
- if (mark[0] != '_') {
- len += strlen(mark) + 2;
- }
- }
- char *buffer = calloc(len + 1, 1);
- char *part = malloc(len + 1);
-
- if (!sway_assert(buffer && part, "Unable to allocate memory")) {
- free(buffer);
- return;
- }
-
- for (int i = 0; i < view->marks->length; ++i) {
- char *mark = view->marks->items[i];
- if (mark[0] != '_') {
- sprintf(part, "[%s]", mark);
- strcat(buffer, part);
- }
- }
- free(part);
-
- double scale = output->wlr_output->scale;
- int width = 0;
- int height = view->container->title_height * scale;
-
- cairo_t *c = cairo_create(NULL);
- get_text_size(c, config->font, &width, NULL, NULL, scale, false,
- "%s", buffer);
- cairo_destroy(c);
-
- cairo_surface_t *surface = cairo_image_surface_create(
- CAIRO_FORMAT_ARGB32, width, height);
- cairo_t *cairo = cairo_create(surface);
- cairo_set_source_rgba(cairo, class->background[0], class->background[1],
- class->background[2], class->background[3]);
- cairo_paint(cairo);
- PangoContext *pango = pango_cairo_create_context(cairo);
- cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST);
- cairo_set_source_rgba(cairo, class->text[0], class->text[1],
- class->text[2], class->text[3]);
- cairo_move_to(cairo, 0, 0);
-
- pango_printf(cairo, config->font, scale, false, "%s", buffer);
-
- cairo_surface_flush(surface);
- unsigned char *data = cairo_image_surface_get_data(surface);
- int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
- struct wlr_renderer *renderer = wlr_backend_get_renderer(
- output->wlr_output->backend);
- *texture = wlr_texture_from_pixels(
- renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data);
- cairo_surface_destroy(surface);
- g_object_unref(pango);
- cairo_destroy(cairo);
- free(buffer);
-}
-
-void view_update_marks_textures(struct sway_view *view) {
- if (!config->show_marks) {
- return;
- }
- update_marks_texture(view, &view->marks_focused,
- &config->border_colors.focused);
- update_marks_texture(view, &view->marks_focused_inactive,
- &config->border_colors.focused_inactive);
- update_marks_texture(view, &view->marks_unfocused,
- &config->border_colors.unfocused);
- update_marks_texture(view, &view->marks_urgent,
- &config->border_colors.urgent);
- container_damage_whole(view->container);
-}
-
bool view_is_visible(struct sway_view *view) {
if (view->container->node.destroying) {
return false;
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 27e9ac7a..05cda5c0 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -35,6 +35,10 @@ struct sway_output *workspace_get_initial_output(const char *name) {
struct workspace_config *wsc = workspace_find_config(name);
if (wsc && wsc->output) {
struct sway_output *output = output_by_name(wsc->output);
+ if (!output) {
+ output = output_by_identifier(wsc->output);
+ }
+
if (output) {
return output;
}
@@ -143,7 +147,11 @@ void workspace_consider_destroy(struct sway_workspace *ws) {
static bool workspace_valid_on_output(const char *output_name,
const char *ws_name) {
struct workspace_config *wsc = workspace_find_config(ws_name);
- return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0;
+ char identifier[128];
+ struct sway_output *output = output_by_name(output_name);
+ output_get_identifier(identifier, sizeof(identifier), output);
+
+ return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0 || strcasecmp(identifier, output_name) == 0;
}
static void workspace_name_from_binding(const struct sway_binding * binding,
diff --git a/swayidle/main.c b/swayidle/main.c
index 93f4c94b..7d0f23f4 100644
--- a/swayidle/main.c
+++ b/swayidle/main.c
@@ -1,4 +1,5 @@
-#define _XOPEN_SOURCE 500
+#define _POSIX_C_SOURCE 200809L
+#include <assert.h>
#include <errno.h>
#include <getopt.h>
#include <pthread.h>
@@ -25,38 +26,24 @@
#include <elogind/sd-login.h>
#endif
-typedef void (*timer_callback_func)(void *data);
-
static struct org_kde_kwin_idle *idle_manager = NULL;
static struct wl_seat *seat = NULL;
-bool debug = false;
struct swayidle_state {
struct wl_display *display;
- struct org_kde_kwin_idle_timeout *idle_timer;
- struct org_kde_kwin_idle_timeout *lock_timer;
struct wl_event_loop *event_loop;
- list_t *timeout_cmds;
+ list_t *timeout_cmds; // struct swayidle_timeout_cmd *
+ char *lock_cmd;
} state;
-struct swayidle_cmd {
- timer_callback_func callback;
- char *param;
-};
-
-struct swayidle_cmd *lock_cmd = NULL;
-
struct swayidle_timeout_cmd {
- uint32_t timeout;
- struct swayidle_cmd *idle_cmd;
- struct swayidle_cmd *resume_cmd;
+ int timeout, registered_timeout;
+ struct org_kde_kwin_idle_timeout *idle_timer;
+ char *idle_cmd;
+ char *resume_cmd;
};
-static void cmd_exec(void *data) {
- if (data == NULL) {
- return;
- }
- char *param = (char *)data;
+static void cmd_exec(char *param) {
wlr_log(WLR_DEBUG, "Cmd exec %s", param);
pid_t pid = fork();
if (pid == 0) {
@@ -82,6 +69,7 @@ static void cmd_exec(void *data) {
#if defined(SWAY_IDLE_HAS_SYSTEMD) || defined(SWAY_IDLE_HAS_ELOGIND)
static int lock_fd = -1;
static int ongoing_fd = -1;
+static struct sd_bus *bus = NULL;
static int release_lock(void *data) {
wlr_log(WLR_INFO, "Releasing sleep lock %d", ongoing_fd);
@@ -92,19 +80,10 @@ static int release_lock(void *data) {
return 0;
}
-void acquire_sleep_lock(void) {
- sd_bus_message *msg = NULL;
- sd_bus_error error = SD_BUS_ERROR_NULL;
- struct sd_bus *bus;
- int ret = sd_bus_default_system(&bus);
-
- if (ret < 0) {
- wlr_log(WLR_ERROR, "Failed to open D-Bus connection: %s",
- strerror(-ret));
- return;
- }
-
- ret = sd_bus_call_method(bus, "org.freedesktop.login1",
+static void acquire_sleep_lock(void) {
+ sd_bus_message *msg;
+ sd_bus_error error;
+ int ret = sd_bus_call_method(bus, "org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager", "Inhibit",
&error, &msg, "ssss", "sleep", "swayidle",
@@ -112,14 +91,16 @@ void acquire_sleep_lock(void) {
if (ret < 0) {
wlr_log(WLR_ERROR, "Failed to send Inhibit signal: %s",
strerror(-ret));
- } else {
- ret = sd_bus_message_read(msg, "h", &lock_fd);
- if (ret < 0) {
- wlr_log(WLR_ERROR,
- "Failed to parse D-Bus response for Inhibit: %s",
- strerror(-ret));
- }
+ return;
+ }
+
+ ret = sd_bus_message_read(msg, "h", &lock_fd);
+ if (ret < 0) {
+ wlr_log(WLR_ERROR, "Failed to parse D-Bus response for Inhibit: %s",
+ strerror(-ret));
+ return;
}
+
wlr_log(WLR_INFO, "Got sleep lock: %d", lock_fd);
}
@@ -140,8 +121,8 @@ static int prepare_for_sleep(sd_bus_message *msg, void *userdata,
ongoing_fd = lock_fd;
- if (lock_cmd && lock_cmd->callback) {
- lock_cmd->callback(lock_cmd->param);
+ if (state.lock_cmd) {
+ cmd_exec(state.lock_cmd);
}
if (ongoing_fd >= 0) {
@@ -149,6 +130,7 @@ static int prepare_for_sleep(sd_bus_message *msg, void *userdata,
wl_event_loop_add_timer(state.event_loop, release_lock, NULL);
wl_event_source_timer_update(source, 1000);
}
+
wlr_log(WLR_DEBUG, "Prepare for sleep done");
return 0;
}
@@ -161,9 +143,7 @@ static int dbus_event(int fd, uint32_t mask, void *data) {
return 1;
}
-void setup_sleep_listener(void) {
- struct sd_bus *bus;
-
+static void setup_sleep_listener(void) {
int ret = sd_bus_default_system(&bus);
if (ret < 0) {
wlr_log(WLR_ERROR, "Failed to open D-Bus connection: %s",
@@ -203,6 +183,7 @@ static void handle_global(void *data, struct wl_registry *registry,
static void handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name) {
+ // Who cares
}
static const struct wl_registry_listener registry_listener = {
@@ -210,19 +191,42 @@ static const struct wl_registry_listener registry_listener = {
.global_remove = handle_global_remove,
};
+static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener;
+
+static void register_timeout(struct swayidle_timeout_cmd *cmd,
+ int timeout) {
+ if (cmd->idle_timer != NULL) {
+ org_kde_kwin_idle_timeout_destroy(cmd->idle_timer);
+ cmd->idle_timer = NULL;
+ }
+ if (timeout < 0) {
+ wlr_log(WLR_DEBUG, "Not registering idle timeout");
+ return;
+ }
+ wlr_log(WLR_DEBUG, "Register with timeout: %d", timeout);
+ cmd->idle_timer =
+ org_kde_kwin_idle_get_idle_timeout(idle_manager, seat, timeout);
+ org_kde_kwin_idle_timeout_add_listener(cmd->idle_timer,
+ &idle_timer_listener, cmd);
+ cmd->registered_timeout = timeout;
+}
+
static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
struct swayidle_timeout_cmd *cmd = data;
wlr_log(WLR_DEBUG, "idle state");
- if (cmd && cmd->idle_cmd && cmd->idle_cmd->callback) {
- cmd->idle_cmd->callback(cmd->idle_cmd->param);
+ if (cmd->idle_cmd) {
+ cmd_exec(cmd->idle_cmd);
}
}
static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) {
struct swayidle_timeout_cmd *cmd = data;
wlr_log(WLR_DEBUG, "active state");
- if (cmd && cmd->resume_cmd && cmd->resume_cmd->callback) {
- cmd->resume_cmd->callback(cmd->resume_cmd->param);
+ if (cmd->registered_timeout != cmd->timeout) {
+ register_timeout(cmd, cmd->timeout);
+ }
+ if (cmd->resume_cmd) {
+ cmd_exec(cmd->resume_cmd);
}
}
@@ -231,20 +235,17 @@ static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
.resumed = handle_resume,
};
-struct swayidle_cmd *parse_command(int argc, char **argv) {
+static char *parse_command(int argc, char **argv) {
if (argc < 1) {
- wlr_log(WLR_ERROR, "Too few parameters for command in parse_command");
+ wlr_log(WLR_ERROR, "Missing command");
return NULL;
}
- struct swayidle_cmd *cmd = calloc(1, sizeof(struct swayidle_cmd));
wlr_log(WLR_DEBUG, "Command: %s", argv[0]);
- cmd->callback = cmd_exec;
- cmd->param = argv[0];
- return cmd;
+ return strdup(argv[0]);
}
-int parse_timeout(int argc, char **argv) {
+static int parse_timeout(int argc, char **argv) {
if (argc < 3) {
wlr_log(WLR_ERROR, "Too few parameters to timeout command. "
"Usage: timeout <seconds> <command>");
@@ -258,9 +259,15 @@ int parse_timeout(int argc, char **argv) {
"numeric value representing seconds", optarg);
exit(-1);
}
+
struct swayidle_timeout_cmd *cmd =
calloc(1, sizeof(struct swayidle_timeout_cmd));
- cmd->timeout = seconds * 1000;
+
+ if (seconds > 0) {
+ cmd->timeout = seconds * 1000;
+ } else {
+ cmd->timeout = -1;
+ }
wlr_log(WLR_DEBUG, "Register idle timeout at %d ms", cmd->timeout);
wlr_log(WLR_DEBUG, "Setup idle");
@@ -276,27 +283,27 @@ int parse_timeout(int argc, char **argv) {
return result;
}
-int parse_sleep(int argc, char **argv) {
+static int parse_sleep(int argc, char **argv) {
if (argc < 2) {
wlr_log(WLR_ERROR, "Too few parameters to before-sleep command. "
"Usage: before-sleep <command>");
exit(-1);
}
- lock_cmd = parse_command(argc - 1, &argv[1]);
- if (lock_cmd) {
- wlr_log(WLR_DEBUG, "Setup sleep lock: %s", lock_cmd->param);
+ state.lock_cmd = parse_command(argc - 1, &argv[1]);
+ if (state.lock_cmd) {
+ wlr_log(WLR_DEBUG, "Setup sleep lock: %s", state.lock_cmd);
}
return 2;
}
+static int parse_args(int argc, char *argv[]) {
+ bool debug = false;
-int parse_args(int argc, char *argv[]) {
int c;
-
- while ((c = getopt(argc, argv, "hs:d")) != -1) {
- switch(c) {
+ while ((c = getopt(argc, argv, "hd")) != -1) {
+ switch (c) {
case 'd':
debug = true;
break;
@@ -311,13 +318,7 @@ int parse_args(int argc, char *argv[]) {
}
}
- if (debug) {
- wlr_log_init(WLR_DEBUG, NULL);
- wlr_log(WLR_DEBUG, "Loglevel debug");
- } else {
- wlr_log_init(WLR_INFO, NULL);
- }
-
+ wlr_log_init(debug ? WLR_DEBUG : WLR_INFO, NULL);
state.timeout_cmds = create_list();
@@ -331,24 +332,36 @@ int parse_args(int argc, char *argv[]) {
i += parse_sleep(argc - i, &argv[i]);
} else {
wlr_log(WLR_ERROR, "Unsupported command '%s'", argv[i]);
- exit(-1);
+ return 1;
}
}
+
return 0;
}
void sway_terminate(int exit_code) {
- if (state.event_loop) {
- wl_event_loop_destroy(state.event_loop);
- }
- if (state.display) {
- wl_display_disconnect(state.display);
- }
+ wl_display_disconnect(state.display);
+ wl_event_loop_destroy(state.event_loop);
exit(exit_code);
}
-void sig_handler(int signal) {
- sway_terminate(0);
+static void register_zero_idle_timeout(void *item) {
+ struct swayidle_timeout_cmd *cmd = item;
+ register_timeout(cmd, 0);
+}
+
+static int handle_signal(int sig, void *data) {
+ switch (sig) {
+ case SIGINT:
+ case SIGTERM:
+ sway_terminate(0);
+ return 0;
+ case SIGUSR1:
+ wlr_log(WLR_DEBUG, "Got SIGUSR1");
+ list_foreach(state.timeout_cmds, register_zero_idle_timeout);
+ return 1;
+ }
+ assert(false); // not reached
}
static int display_event(int fd, uint32_t mask, void *data) {
@@ -359,33 +372,26 @@ static int display_event(int fd, uint32_t mask, void *data) {
wlr_log_errno(WLR_ERROR, "wl_display_dispatch failed, exiting");
sway_terminate(0);
}
+ wl_display_flush(state.display);
return 0;
}
-void register_idle_timeout(void *item) {
+static void register_idle_timeout(void *item) {
struct swayidle_timeout_cmd *cmd = item;
- if (cmd == NULL || !cmd->timeout) {
- wlr_log(WLR_ERROR, "Invalid idle cmd, will not register");
- return;
- }
- state.idle_timer =
- org_kde_kwin_idle_get_idle_timeout(idle_manager, seat, cmd->timeout);
- if (state.idle_timer != NULL) {
- org_kde_kwin_idle_timeout_add_listener(state.idle_timer,
- &idle_timer_listener, cmd);
- } else {
- wlr_log(WLR_ERROR, "Could not create idle timer");
- }
+ register_timeout(cmd, cmd->timeout);
}
int main(int argc, char *argv[]) {
- signal(SIGINT, sig_handler);
- signal(SIGTERM, sig_handler);
-
if (parse_args(argc, argv) != 0) {
return -1;
}
+ state.event_loop = wl_event_loop_create();
+
+ wl_event_loop_add_signal(state.event_loop, SIGINT, handle_signal, NULL);
+ wl_event_loop_add_signal(state.event_loop, SIGTERM, handle_signal, NULL);
+ wl_event_loop_add_signal(state.event_loop, SIGUSR1, handle_signal, NULL);
+
state.display = wl_display_connect(NULL);
if (state.display == NULL) {
wlr_log(WLR_ERROR, "Unable to connect to the compositor. "
@@ -397,7 +403,6 @@ int main(int argc, char *argv[]) {
struct wl_registry *registry = wl_display_get_registry(state.display);
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(state.display);
- state.event_loop = wl_event_loop_create();
if (idle_manager == NULL) {
wlr_log(WLR_ERROR, "Display doesn't support idle protocol");
@@ -410,7 +415,7 @@ int main(int argc, char *argv[]) {
bool should_run = state.timeout_cmds->length > 0;
#if defined(SWAY_IDLE_HAS_SYSTEMD) || defined(SWAY_IDLE_HAS_ELOGIND)
- if (lock_cmd) {
+ if (state.lock_cmd) {
should_run = true;
setup_sleep_listener();
}
@@ -419,12 +424,15 @@ int main(int argc, char *argv[]) {
wlr_log(WLR_INFO, "No command specified! Nothing to do, will exit");
sway_terminate(0);
}
+
list_foreach(state.timeout_cmds, register_idle_timeout);
wl_display_roundtrip(state.display);
- wl_event_loop_add_fd(state.event_loop, wl_display_get_fd(state.display),
- WL_EVENT_READABLE, display_event, NULL);
+ struct wl_event_source *source = wl_event_loop_add_fd(state.event_loop,
+ wl_display_get_fd(state.display), WL_EVENT_READABLE,
+ display_event, NULL);
+ wl_event_source_check(source);
while (wl_event_loop_dispatch(state.event_loop, -1) != 1) {
// This space intentionally left blank
diff --git a/swayidle/swayidle.1.scd b/swayidle/swayidle.1.scd
index 7c1b138a..3083163f 100644
--- a/swayidle/swayidle.1.scd
+++ b/swayidle/swayidle.1.scd
@@ -22,11 +22,13 @@ swayidle listens for idle activity on your Wayland compositor and executes tasks
on various idle-related events. You can specify any number of events at the
command line.
+Sending SIGUSR1 to swayidle will immediately enter idle state.
+
# EVENTS
*timeout* <timeout> <timeout command> [resume <resume command>]
Execute _timeout command_ if there is no activity for <timeout> seconds.
-
+
If you specify "resume <resume command>", _resume command_ will be run when
there is activity again.
@@ -39,11 +41,11 @@ All commands are executed in a shell.
# EXAMPLE
```
- swayidle \
- timeout 300 'swaylock -c 000000' \
- timeout 600 'swaymsg "output * dpms off"' \
+swayidle \
+ timeout 300 'swaylock -c 000000' \
+ timeout 600 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
- before-sleep 'swaylock -c 000000'
+ before-sleep 'swaylock -c 000000'
```
This will lock your screen after 300 seconds of inactivity, then turn off your
@@ -58,4 +60,4 @@ https://github.com/swaywm/sway.
# SEE ALSO
-*sway*(5) *swaymsg*(1) *sway-input*(5) *sway-bar*(5)
+*sway*(5) *swaymsg*(1) *sway-input*(5) *sway-output*(5) *sway-bar*(5)
diff --git a/swaylock/swaylock.1.scd b/swaylock/swaylock.1.scd
index 3107124f..8ddc7d3a 100644
--- a/swaylock/swaylock.1.scd
+++ b/swaylock/swaylock.1.scd
@@ -21,20 +21,25 @@ Locks your Wayland session.
All leading dashes should be omitted and the equals sign is required for
flags that take an argument.
-*-c, --color* <rrggbb[aa]>
- Turn the screen into the given color. If -i is used, this sets the
- background of the image to the given color. Defaults to white (FFFFFF), or
- transparent (00000000) if an image is in use.
-
*-e, --ignore-empty-password*
When an empty password is provided by the user, do not validate it.
*-f, --daemonize*
Detach from the controlling terminal after locking.
+ Note: this is the default bahavior of i3lock.
+
*-h, --help*
Show help message and quit.
+*-v, --version*
+ Show the version number and quit.
+
+# APPEARANCE
+
+*-u, --no-unlock-indicator*
+ Disable the unlock indicator.
+
*-i, --image* [<output>:]<path>
Display the given image, optionally only on the given output. Use -c to set
a background color.
@@ -45,13 +50,10 @@ Locks your Wayland session.
*-t, --tiling*
Same as --scaling=tile.
-*-u, --no-unlock-indicator*
- Disable the unlock indicator.
-
-*-v, --version*
- Show the version number and quit.
-
-# APPEARANCE
+*-c, --color* <rrggbb[aa]>
+ Turn the screen into the given color. If -i is used, this sets the
+ background of the image to the given color. Defaults to white (FFFFFF), or
+ transparent (00000000) if an image is in use.
*--bs-hl-color* <rrggbb[aa]>
Sets the color of backspace highlight segments.
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 4688737c..e13dd7ec 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -23,7 +23,7 @@ static bool success_object(json_object *result) {
json_object *success;
if (!json_object_object_get_ex(result, "success", &success)) {
- return false;
+ return true;
}
return json_object_get_boolean(success);
@@ -183,13 +183,15 @@ static void pretty_print_output(json_object *o) {
json_object_object_get_ex(rect, "height", &height);
json_object *modes;
json_object_object_get_ex(o, "modes", &modes);
+ json_object *current_mode;
+ json_object_object_get_ex(o, "current_mode", &current_mode);
if (json_object_get_boolean(active)) {
printf(
"Output %s '%s %s %s'%s\n"
" Current mode: %dx%d @ %f Hz\n"
" Position: %d,%d\n"
- " Scale factor: %dx\n"
+ " Scale factor: %f\n"
" Transform: %s\n"
" Workspace: %s\n",
json_object_get_string(name),
@@ -197,10 +199,13 @@ static void pretty_print_output(json_object *o) {
json_object_get_string(model),
json_object_get_string(serial),
json_object_get_boolean(focused) ? " (focused)" : "",
- json_object_get_int(width), json_object_get_int(height),
+ json_object_get_int(
+ json_object_object_get(current_mode, "width")),
+ json_object_get_int(
+ json_object_object_get(current_mode, "height")),
(float)json_object_get_int(refresh) / 1000,
json_object_get_int(x), json_object_get_int(y),
- json_object_get_int(scale),
+ json_object_get_double(scale),
json_object_get_string(transform),
json_object_get_string(ws)
);