Commit Graph

189 Commits

Author SHA1 Message Date
Antonin Décimo a1c6052383 Log empty value if envvar is not defined
If the environment variable is not defined, getenv returns NULL.
Passing a NULL pointer to the "%s" format specifier is undefined
behavior. Even if some implementations output "(null)", an empty
string is nicer.
2020-07-30 22:02:42 -04:00
Simon Ser bf8d23a836 Log Sway version on startup 2020-06-11 08:44:09 -06:00
Brian Ashworth 33a984bbc5 config: fix validation exit code and log level
This makes it so invalid configs will return the exit code 1 when the
validation flag is given. This also reduces the log level to SWAY_ERROR,
which makes it so only the errors are shown. If someone wants more
verbose output, the can use the -V/--verbose or -d/--debug flags.
Additionally, this also makes it so swaybg will not be spawned when
validating the config.
2020-02-11 16:02:11 +01:00
Teddy Reed 31a83bd48d Fix ordering of setgid and setuid
It looks like the code to drop privileges may have been broken via
commit 37f0e1f. That commit reverted the correct order from #911, which
first drops the gid then the uid. If setuid is called first then the
target user may not have the ability to setgid.
2020-02-11 10:17:45 +01:00
thermitegod 29a5ce5f65 Fix compiling with -fno-common 2020-01-24 10:16:59 +01:00
lbonn a6307aed00 Fix various memory leaks
Found with clang-tidy
2019-11-01 12:18:09 -04:00
Simon Ser c41c24d684 Error out on unknown debug flag
Otehrwise it's pretty easy to misremember a flag and think damage=rerender is
enabled when it's not.
2019-09-22 15:17:59 -04:00
Brian Ashworth 9670ccee68 bindings: defer while initiailizing
This adds the logic to defer binding execution while sway is still
initializing. Without this, the binding command would be executed, but
the command handler would return CMD_DEFER, which was being treated as
a failure to run. To avoid partial executions, this will defer all
bindings while config->active is false.
2019-06-12 07:56:41 +03:00
Lane Surface 812651d53e Remove extra inclusion of stdio.h 2019-04-27 20:53:21 -06:00
Brian Ashworth 6961bf2e4c Spawn swaynag as a wayland client
This spawns swaynag as a wayland client similar to how swaybar and
swaybg are already done
2019-04-14 12:41:59 +03:00
Ryan Dwyer e9a476244d Remove debug tree
This feature has served its purpose. It's better to use IPC now.
2019-03-18 11:29:19 -04:00
Brian Ashworth 20c4d242f6 detect_proprietary: use strncmp
Only the main nvidia module needs to be blocked. Others such as
nvidiafb are benign and do not need to be blocked
2019-03-10 22:16:09 -06:00
hugbubby 37f0e1f1a2 Minor fix of code duplication.
Removes 3~ lines of code that didn't need to be restated.
2019-03-02 00:49:02 +01:00
Rouven Czerwinski aa4ccd845c run_as_ipc_client: free response after running the IPC command
Fixes memory leaks in the form of:

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f5f7c2f4f30 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xedf30)
    #1 0x563c799569f2 in ipc_recv_response ../common/ipc-client.c:94
    #2 0x563c79957062 in ipc_single_command ../common/ipc-client.c:138
    #3 0x563c798a56cc in run_as_ipc_client ../sway/main.c:127
    #4 0x563c798a6a3a in main ../sway/main.c:349
    #5 0x7f5f7b4d609a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
2019-02-21 11:32:55 +01:00
Rouven Czerwinski a968a650e2 ipc-client: free payload after sending it over the socket
Fixes memory leaks in the form of:

Direct leak of 20 byte(s) in 1 object(s) allocated from:
    #0 0x7f5f7c2f4f30 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xedf30)
    #1 0x563c7995b36a in join_args ../common/stringop.c:268
    #2 0x563c798a6a1a in main ../sway/main.c:348
    #3 0x7f5f7b4d609a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
2019-02-21 11:31:05 +01:00
Brian Ashworth 2540e8ea79 Abort early when XDG_RUNTIME_DIR is not set
This aborts sway and displays an error message about XDG_RUNTIME_DIR
not being set without initializing the wl_display or logging any other
information.
2019-02-11 10:11:41 +01:00
Brian Ashworth ee56428b64 Clarify error for options and positional args
When both options and positional arguments are given, sway would print
the error `Don't use options with the IPC client`. Over the past
several months, it seems like users are including this error message in
issues instead of a debug log due to not understanding that the error
message means there is an issue with their command.

This makes the error message more verbose and will hopefully make it so
more users understand that the message is not a bug in sway, but with
the command used.
2019-02-06 19:38:25 +01:00
Connor E e1b8190d2c Initialize server so input manager is available. 2019-02-05 15:39:22 +00:00
Connor E 886789c197 If validating the config, do it as early as possible. 2019-02-05 14:37:22 +00:00
Brian Ashworth f0fd6119cf Cleanup config reading failure error logs
This cleans up the log when sway fails to read a config file. The
following changes have been made:
- A missing error message has been added to the log when the config file
is a directory instead of a regular file
- In main, `goto` statements have been added after the `sway_terminate`
calls instead of wrapping every block in `if (!terminate_request)`
- Unnecessary NULL-checks around calls to free in `main` have been
removed
- Deferred command execution has been extracted to a separate function
and the `Running deferred commands` log message will not be shown when
there are no deferred commands.
2019-01-29 13:18:53 -05:00
emersion 7c72327ab5
Cleanup log_env
SWAY_CURSOR_* are not used anymore. LD_PRELOAD_PATH doesn't exist and has been
replaced with LD_PRELOAD.
2019-01-28 21:59:10 +01:00
M Stoeckl 1211a81aad Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although
with a sway_* prefix. (This is very similar to PR #2009.)
However, the logging function no longer needs to be replaceable,
so sway_log_init's second argument is used to set the exit
callback for sway_abort.

wlr_log_init is still invoked in sway/main.c

This commit makes it easier to remove the wlroots dependency for
the helper programs swaymsg, swaybg, swaybar, and swaynag.
2019-01-21 12:59:42 +01:00
Brian Ashworth 686b853047 Do not send ipc_event_shutdown from ipc client
In `sway_terminate`, `ipc_event_shutdown` was being sent regardless
which mode sway was running in. When running as an ipc client,
`sway_terminate` should just exit
2019-01-15 22:41:54 +01:00
Drew DeVault 4879d40695
Merge pull request #3144 from emersion/cmd-xwayland
Add xwayland command
2019-01-13 20:42:39 -05:00
Ian Fan a82b8a3c14 Remove readline.c
All occurrences of read_line have been replaced by getline.
peek_line has been absorbed into detect_brace.
2019-01-01 09:01:25 +00:00
Ian Fan c8776fac42 Cleanup list code 2018-12-09 01:15:38 +00:00
Brian Ashworth 5c6f3d7266 Change execute_command to return a list of results
This matches i3's behavior of returning a list of results that contain
the result of each command that was executed. Additionally, the
`parse_error` attribute has been added to the IPC JSON reply.
2018-11-27 21:42:09 -05:00
emersion 3a310f92ab
Replace _XOPEN_SOURCE with _POSIX_C_SOURCE
And make sure we don't define both in the same source file.
2018-11-25 17:19:43 +01:00
emersion 311c7db7e3
Add xwayland command 2018-11-19 17:38:37 +01:00
emersion f90ff1210b
Teardown compositor when failing to drop permissions 2018-11-01 18:50:06 +01:00
emersion 9dae68eba5
Make it clear that being able to restore root is a failure 2018-11-01 18:49:42 +01:00
Ryan Dwyer ebeb759873 Abort if proprietary drivers are in use
The idea here is we don't want users to be blissfully unaware that they
are running unsupported drivers. So we abort on startup, and force the
user to add a specific argument to bypass the check.
2018-10-21 00:01:09 +10:00
Drew DeVault 71aaa7e130 Remove unnecessary comment 2018-10-13 20:51:29 -04:00
Arkadiusz Hiler eed0bc3ebd Add support for installing binaries with DT_RPATH
It's better to use DT_RPATH dynamic section of the elf binary to store
the paths of libraries to load instead of overwriting LD_LIBRARY_PATH
for the whole environment, causing surprises. This solution is much more
transparent and perfectly suitable for running contained installations
of wayland/wlroots/sway.

The code unsetting the LD_LIBRARY_PATH/LD_PRELOAD was also deleted as
it's a placebo security at best - we should trust the execution path
that leads us to running sway, and it's way too late to care about those
variables since we already started executing our compositor, thus we
would be compromised anyway.
2018-09-30 15:37:01 +03:00
Arkadiusz Hiler 1e70f7b19e Turn funcs() into funcs(void)
If they really do not take undefined number of arguments.
2018-09-30 14:09:05 +03:00
Arkadiusz Hiler 00dfb76832 Remove libcap/prctl artifacts
They seem like relics of the pasts, from when we were retaining the
ptrace cap.

Some translations still may need updates.
2018-09-30 13:39:26 +03:00
Ryan Dwyer cb66bbea42 Allow running commands on containers without focusing them
This adds a `con` argument to `execute_command` which allows you to
specify the container to execute the command on. In most cases it leaves
it as `NULL` which makes it use the focused node. We only set it when
executing `for_window` criteria such as when a view maps. This means we
don't send unnecessary IPC focus events, and fixes a crash when the
criteria command is `move scratchpad` (because we can't give focus to a
hidden scratchpad container).

Each of the shell map handlers now check to see if the view has a
workspace. It won't have a workspace if criteria has moved it to the
scratchpad.
2018-09-23 08:39:11 +10:00
emersion 82f1393cbb swaybar: handle hotplugging
Don't kill and respawn swaybars on hotplug.
2018-09-20 18:37:51 +02:00
Ryan Dwyer 7586f150c0 Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.

In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.

If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.

There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.

In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.

The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.

The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.

Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.

Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.

In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.

container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.

`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.

container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.

There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.

The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-09-05 18:01:43 +10:00
sghctoma 67188b7cba Enable privilege dropping of FreeBSD
Privilege dropping works on FreeBSD too, so only the caps parts need to
be Linux-only.
2018-08-30 10:33:48 +02:00
Ryan Dwyer 5dbbab7bdc Remove layout.c
When we have type safety we'll need to have functions for
workspace_add_tiling and so on. This means the existing container
functions will be just for containers, so they are being moved to
container.c. At this point layout.c doesn't contain much else, so I've
relocated everything and removed the file.

* container_swap and its static functions have been moved to the swap
command and made static.
* container_recursive_resize has been moved to the resize command and
made static.
* The following have been moved to container.c:
    * container_handle_fullscreen_reparent
    * container_insert_child
    * container_add_sibling
    * container_add_child
    * container_remove_child
    * container_replace_child
    * container_split
* enum movement_direction and sway_dir_to_wlr have been moved to util.c.

Side note: Several commands included layout.h which then included
root.h. With layout.h gone, root.h has to be included by those commands.
2018-08-26 12:05:16 +10:00
Ryan Dwyer f9563d88f3 Use enum for damage debug options 2018-08-19 16:17:24 +10:00
Ryan Dwyer 8d1dd03823 Standardise debug variables
This makes all debug options stored in a single struct rather than in
various places, changes/fixes the behaviour of existing options, and
introduces some new options.

* Fixes damage issues with `-Drender-tree` texture (by removing scissor)
* Offsets the render tree overlay's `y` position for those who have
swaybar at the top
* Replaces `-Ddamage=rerender` with `-Dnodamage`
* Replaces `-Ddamage=highlight` with `-Dhighlight-damage`
* Replaces `-Dtxn-debug` with `-Dtxn-wait`
* Introduces `-Dnoatomic`
* Removes the `create_time` and `ms_arranging` figures from transactions
and the log message. Transactions are created after arranging and the
create time is of no significance.
* Fixes `-Dtxn-debug` (now `-Dtxn-wait`) not working.
2018-08-19 16:17:24 +10:00
Drew DeVault db0fa066e5 Remove obsolete security sanity check 2018-08-09 08:45:32 -04:00
Ryan Dwyer 04489ff420 Separate root-related code
This creates a root.c and moves bits and pieces from elsewhere into it.

* layout_init has been renamed to root_create and moved into root.c
* root_destroy has been created and is called on shutdown
* scratchpad code has been moved into root.c, because hidden scratchpad
containers are stored in the root struct
2018-08-04 14:01:20 +10:00
Brian Ashworth a7f7d4a488 Write to swaynag pipe fd directly on config errors 2018-08-03 10:37:35 -04:00
Brian Ashworth f9a6407111 Show swaynag on config errors 2018-08-03 10:37:35 -04:00
Ian Fan e8b179e313 ipc: add shutdown event 2018-08-01 16:57:14 +01:00
Brian Ashworth ec65286606 Fix deferred command handling 2018-07-19 01:39:58 -04:00
Ryan Dwyer a120d4c79f Make focus part of transactions
Rather than maintain copies of the entire focus stack, this PR
transactionises the focus by introducing two new properties to the
container state and using those when rendering.

* `bool focused` means this container has actual focus. Only one
container should have this equalling true in its current state.
* `struct sway_container *focus_inactive_child` points to the immediate
child that was most recently focused (eg. for tabbed and stacked
containers).
2018-07-15 22:08:26 +10:00