Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port swaylock to layer shell #1705

Merged
merged 19 commits into from
Apr 5, 2018
Merged

Port swaylock to layer shell #1705

merged 19 commits into from
Apr 5, 2018

Conversation

ddevault
Copy link
Contributor

@ddevault ddevault commented Apr 3, 2018

Fixes #1506, fixes #1141, fixes #918, fixes #605, fixes #1072

Ref #797

@ddevault ddevault force-pushed the swaylock-layers branch 2 times, most recently from fec70c9 to fc2b037 Compare April 3, 2018 19:27
@@ -9,6 +9,7 @@ lib_sway_common = static_library(
'pango.c',
'readline.c',
'stringop.c',
'unicode.c',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use mbrtoc32/c32rtomb from <uchar.h>, instead of doing it ourselves?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not portable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're standard C11 functions. I'm not certain, but they may introduce some locale-specific shit, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like uchar.h is pretty shit after further research. It doesn't guarantee UTF-8 on the other side, just some locale-specific nonsense. I like my stock functions.

@ddevault ddevault force-pushed the swaylock-layers branch 5 times, most recently from 5beea9e to e79ef49 Compare April 3, 2018 23:15
@ddevault ddevault changed the title [WIP] Port swaylock to layer shell Port swaylock to layer shell Apr 3, 2018
@ddevault
Copy link
Contributor Author

ddevault commented Apr 3, 2018

This is ready for review.

while the inhibitor is active.

The compositor may continue to send input events to selected clients,
such as an on-screen keyboard (via the input-method protocol).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the input-method protocol?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in wayland-protocols

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could qualify this a bit better.

if (previous) {
wlr_log(L_DEBUG, "Returning focus to %p %s '%s'", previous,
container_type_to_str(previous->type), previous->name);
// Hack to get seat to re-focus the return value of get_focus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we handled focus out of the context of the seat's normal focus handling, seat_get_focus still returns what was focused before. Calling seat_set_focus with the return value of seat_get_focus (rightfully) exits early without doing anything, given that the previous focus is still valid. To work around this the hack changes the focus to the parent, then back again.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you considered using the send_focus function?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be better, set focus to NULL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% on the best way to refactor this, I would appreciate it if you filed a follow-up patch improving it if you're not happy with it

@@ -350,6 +353,11 @@ void seat_configure_xcursor(struct sway_seat *seat) {
seat->cursor->cursor->y);
}

bool seat_allow_input(struct sway_seat *seat, struct wlr_surface *surface) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functions that return bools should be like input_is_allowed or input_allowed. This sounds like it makes input allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *output = root_container.children->items[i];
if (!sway_assert(output->type == C_OUTPUT,
"root container has non-output child")) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on i3, the scratchpad is a child of the root container.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on sway it won't be

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be represented that way in the ipc get_tree or you'll break people's scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted

Clients can use this interface to prevent input events from being sent to
any surfaces but its own, which is useful for example in lock screen
software. It is assumed that access to this interface will be locked down
to whitelisted clients by the compositor.
Copy link

@acrisci acrisci Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should specify what happens to input focus of the existing clients when this gets created (and destroyed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move protocol feedback to the wlr-protocols thread

seat_set_focus(seat, NULL);
}
}
if (seat->wlr_seat->pointer_state.focused_client) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want library users to dig into pointer_state. What about making a getter for this now that it's important?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

wl_list_for_each(point, &seat->wlr_seat->touch_state.touch_points, link) {
if (point->client->client != client) {
wlr_seat_touch_point_clear_focus(seat->wlr_seat,
now.tv_nsec / 1000, point->touch_id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this way of getting the time compatible with what we get from the real events?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya

wl_surface_attach(surface->surface, surface->current_buffer->buffer, 0, 0);
wl_surface_damage(surface->surface, 0, 0, buffer_width, buffer_height);
wl_surface_commit(surface->surface);
wl_display_roundtrip(state->display);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you roundtripping here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sway/swaylock/password.c

Lines 102 to 108 in e79ef49

state->auth_state = AUTH_STATE_VALIDATING;
render_frames(state);
if (attempt_password(&state->password)) {
exit(0);
}
state->auth_state = AUTH_STATE_INVALID;
render_frames(state);

@acrisci
Copy link

acrisci commented Apr 4, 2018

It doesn't compile. I don't have rand().

@acrisci
Copy link

acrisci commented Apr 4, 2018

I don't have exit(). You should include stdlib.h.

@acrisci acrisci self-requested a review April 4, 2018 02:16
swaylock/main.c Outdated
surface->image = background_image;

assert(surface->surface =
wl_compositor_create_surface(state.compositor));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No side effects in assertions


static bool backspace(struct swaylock_password *pw) {
if (pw->len != 0) {
pw->buffer[--pw->len] = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: with assignments in ifs, side effects in array brackets are practices I don't like and are error-prone. Especially for a lockscreen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is error prone, this behavior is well defined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying this is undefined behavior, I'm just saying it's unreadable and thus error-prone, even for people used to these idioms. It's just like ifs without brackets.

Anyway, I don't care too much, this is just a warning to say "if there's a bug because of this, don't blame me for having approved this PR".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what you're saying. I disagree.

render_frames(state);
wl_display_roundtrip(state->display);
if (attempt_password(&state->password)) {
exit(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should cleanup all resources.

struct swaylock_state *state = surface->state;
surface->current_buffer = get_next_buffer(state->shm,
surface->buffers,
surface->width * surface->scale,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define buffer_width before this instruction, and replace surface->width * surface->scale with buffer_width

}
cairo_identity_matrix(cairo);

int ARC_RADIUS = 50 * surface->scale;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these in all caps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used to be constants. Will lowercase them now.


wl_surface_set_buffer_scale(surface->surface, surface->scale);
wl_surface_attach(surface->surface, surface->current_buffer->buffer, 0, 0);
wl_surface_damage(surface->surface, 0, 0, buffer_width, buffer_height);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to damage buffer_{width,height}, use wl_surface_damage_buffer. Or you could just use surface->{width,height}.

@emersion emersion merged commit f2153f3 into wlroots Apr 5, 2018
@emersion emersion deleted the swaylock-layers branch April 5, 2018 00:16
@ddevault
Copy link
Contributor Author

ddevault commented Apr 5, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants