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

Log input event details to verbose log #2371

Closed
wants to merge 9 commits into from

Conversation

intgr
Copy link
Contributor

@intgr intgr commented Jun 8, 2021

I wanted to automate a few actions using 'adb shell input' commands, but
it requires pixel coordinates. Logging input event details from scrcpy is
helpful for achieving that.

@intgr
Copy link
Contributor Author

intgr commented Jun 8, 2021

PS: Thanks a lot for developing and maintainig scrcpy. 💘

@intgr intgr changed the title Log finger event coordinates in debug log Log finger event coordinates to debug log Jun 8, 2021
@rom1v
Copy link
Collaborator

rom1v commented Jun 9, 2021

Thank you for your contribution.

I think that the log should not be in the "convert" method (wihch is a kind of util method), but in the caller.

Input events can be very verbose, they should be enabled in verbose mode only (LOGV) IMO.

For consistency, verbose logs could also be added for other input events (keyboard, touches). (This could be done separately later though.)

@intgr
Copy link
Contributor Author

intgr commented Jun 10, 2021

👍 I will try to make changes later today.

@intgr intgr force-pushed the log-finger-event-coordinates branch 2 times, most recently from b65886d to 728f658 Compare June 10, 2021 20:39
@intgr
Copy link
Contributor Author

intgr commented Jun 10, 2021

Fixed your notes and added logging for finger events. Didn't implement keyboard event logging yet.

@rom1v
Copy link
Collaborator

rom1v commented Jun 16, 2021

After reading your LOGV calls just before a control_push_msg(), I'm wondering if we shouldn't log all control messages (with all its values).

For example, by adding a function control_msg_log(const struct control_msg *msg) called at the beginning of control_push_msg(). What do you think?

@intgr
Copy link
Contributor Author

intgr commented Jun 17, 2021

Makes sense to me.

Do you think I should log AMOTION_EVENT_ACTION_MOVE events too or just up/down? For my use case, I would find logging all events a bit noisy.

For example, if I want to script an adb shell input swipe command, I need the start and end coordinates but not the intermediate ones. But I think it isn't a big deal.

Can you imagine any use cases, where logging intermediate events would be useful?

@rom1v
Copy link
Collaborator

rom1v commented Jun 17, 2021

I would prefer to log all events sent to the device without distinction. If you want only some of them, it's easy to grep :)

@intgr intgr force-pushed the log-finger-event-coordinates branch 2 times, most recently from 83e824f to 3fd36c8 Compare June 17, 2021 19:20
@intgr
Copy link
Contributor Author

intgr commented Jun 17, 2021

@rom1v I pushed a partial draft, if you happen to be around, it would be nice to hear if I'm going in the right direction with this.

I also noticed only now (embarrassing!) that scrcpy does not currently support a SC_LOG_LEVEL_VERBOSE log level, I suppose I need to add support for that as well?

@intgr intgr changed the title Log finger event coordinates to debug log Log input event details to verbose log Jun 17, 2021
Copy link
Collaborator

@rom1v rom1v left a comment

Choose a reason for hiding this comment

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

I pushed a partial draft, if you happen to be around, it would be nice to hear if I'm going in the right direction with this.

Yes, looks good 👍 Thank you.

I added few remarks inline.

I also noticed only now (embarrassing!) that scrcpy does not currently support a SC_LOG_LEVEL_VERBOSE log level

Oops.

I suppose I need to add support for that as well?

Yes please, as a separate commit :)

app/src/android/input.h Outdated Show resolved Hide resolved
app/src/controller.c Outdated Show resolved Hide resolved
app/src/controller.c Outdated Show resolved Hide resolved
app/src/controller.c Outdated Show resolved Hide resolved
@intgr intgr force-pushed the log-finger-event-coordinates branch from 3fd36c8 to 2359ffd Compare June 17, 2021 21:40
@intgr
Copy link
Contributor Author

intgr commented Jun 17, 2021

Thanks! My C has been getting a bit rusty. Pushed an updated version.

  • I added --verbosity=verbose option in a separate commit
  • I went through all format string arguments and should have correct types now.
  • Moved logging code to control_msg.c
  • Added remaining event types

I was trying to avoid building the Java part. Took me a while to realize that I need to downgrade, seems like it doesn't work with JDK 16 (got some weird error "module java.base does not "opens java.io" to unnamed module").

@intgr intgr force-pushed the log-finger-event-coordinates branch from 2359ffd to 3d4cb1b Compare June 17, 2021 21:46
break;
case CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT: {
size_t action = msg->inject_touch_event.action & AMOTION_EVENT_ACTION_MASK;
LOGV("Input: touch %-4s position=%" PRIi32 "x%" PRIi32 " pressure=%g buttons=%06lx",
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 omitted pointer_id from this message because it didn't didn't seem very useful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should log it, it allows to distinguish several simultaneous fingers on touch events.

app/src/control_msg.c Outdated Show resolved Hide resolved
@intgr intgr force-pushed the log-finger-event-coordinates branch from 3d4cb1b to 85200bd Compare June 17, 2021 22:01
app/src/cli.c Show resolved Hide resolved
rom1v pushed a commit that referenced this pull request Jun 19, 2021
rom1v pushed a commit that referenced this pull request Jun 19, 2021
@rom1v
Copy link
Collaborator

rom1v commented Jun 19, 2021

Hi,

I allowed myself to work on this based on your branch. I did the following changes:

  • introduce a few more macros to simplify
  • log pointer id (either mouse, vfinger or a numeric id)

Here is a branch: logv. Please review/test 😉

I discovered, thanks to the logs, that motion events were sent even if left-click was not pressed (but for example right-click or 4th button), so I fixed it: 0fd5622 👍

I plan to do few more things before merging:

  • move all log level stuff to log.h/log.c
  • expose a function to know the current log level
  • do not call control_msg_log() if the current log level is not verbose.

rom1v pushed a commit that referenced this pull request Jun 19, 2021
rom1v pushed a commit that referenced this pull request Jun 19, 2021
It was safe to call strcpy() since the input length was checked, but
then it is more straightforward to call memcpy() directly.
rom1v and others added 3 commits June 20, 2021 12:34
Mouse motion events were forwarded as soon as any mouse button was
pressed.

Instead, only consider left-click (and also middle-click and right-click
if --forward-all-clicks is enabled).
rom1v pushed a commit that referenced this pull request Jun 20, 2021
@rom1v
Copy link
Collaborator

rom1v commented Jun 20, 2021

I plan to do few more things before merging:

  • move all log level stuff to log.h/log.c
  • expose a function to know the current log level
  • do not call control_msg_log() if the current log level is not verbose.

Done. I updated the logv branch.

@intgr
Copy link
Contributor Author

intgr commented Jun 20, 2021

I discovered, thanks to the logs, that motion events were sent even if left-click was not pressed

Thanks, cool to hear that there are other use cases/benefits of this work :)

@intgr
Copy link
Contributor Author

intgr commented Jun 20, 2021

How do we proceed? Should I pull your changes to my branch? I'll do that for now.

@intgr intgr force-pushed the log-finger-event-coordinates branch from 85200bd to 3671e55 Compare June 20, 2021 13:08
@rom1v
Copy link
Collaborator

rom1v commented Jun 20, 2021

How do we proceed? Should I pull your changes to my branch?

Not necessarily, just tell me if it's ok or if some thkngs should be changed :) I'll merge manually.

app/src/controller.c Outdated Show resolved Hide resolved
@intgr
Copy link
Contributor Author

intgr commented Jun 20, 2021

Other than that minor comment, this looks good to me.

Not necessarily, just tell me if it's ok or if some thkngs should be changed :) I'll merge manually.

OK, I already pushed it, I'm sure you can sort it out :)

app/src/control_msg.c Outdated Show resolved Hide resolved
intgr and others added 5 commits June 20, 2021 16:03
On Windows, PRIu64 is defined to "llu", which is not supported:

    error: unknown conversion type character 'l' in format
This will allow to avoid unnecessary processing for creating logs which
will be discarded anyway.
If the log level is not verbose, there is no need to attept to log
control messages at all.
@rom1v
Copy link
Collaborator

rom1v commented Jun 20, 2021

OK, I already pushed it, I'm sure you can sort it out :)

OK, it's indeed better that you pushed it, it's more convenient for discussions 😉

@intgr intgr force-pushed the log-finger-event-coordinates branch from 3671e55 to 0de534d Compare June 20, 2021 14:13
@intgr
Copy link
Contributor Author

intgr commented Jun 20, 2021

Pushed again. Seems fine to me now 👍

@rom1v
Copy link
Collaborator

rom1v commented Jun 20, 2021

Seems fine to me now +1

Thanks 👍

Then let's merge into dev 🎉

@rom1v rom1v closed this Jun 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants