Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd Programname and Windowname to logs #152
Conversation
t0mOURCSSn
added some commits
Jul 25, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for this, I'd be honored to accept it. It fulfills one of the first enhancement requests, #3. |
kernc
reviewed
Aug 2, 2016
| //// on processid change update program_info write '[process name] "process title" > ' | ||
| //// on process title change (like firefox tabs) would be better. possibly more ressource intensive? | ||
| if (args.flags & FLAG_PROGRAMINFO) { | ||
| window_id = execute(COMMAND_STR_AWID); |
This comment has been minimized.
This comment has been minimized.
kernc
Aug 2, 2016
Owner
This spawns three new processes on each keypress. This indeed feels somewhat intensive. Did you perhaps investigate how cumbersome the use of relevant Xlib function calls would be?
kernc
reviewed
Aug 2, 2016
| @@ -51,6 +52,7 @@ void process_command_line_arguments(int argc, char **argv) | |||
| {"export-keymap", required_argument, &flags, FLAG_EXPORT_KEYMAP}, | |||
| {"no-func-keys", no_argument, &flags, FLAG_NO_FUNC_KEYS}, | |||
| {"no-timestamps", no_argument, &flags, FLAG_NO_TIMESTAMPS}, | |||
| {"programinfo", no_argument, &flags, FLAG_PROGRAMINFO}, | |||
This comment has been minimized.
This comment has been minimized.
kernc
Aug 2, 2016
Owner
You correctly call it process later on. It's a process that is running and has a window. I would prefer this being exposed as --process-info or --window-title to be more verbose about what this logs (window's name and title, in particular).
kernc
reviewed
Aug 2, 2016
| // active window id, title, name | ||
| #define COMMAND_STR_AWID "xprop -root 32x '\\t$0' _NET_ACTIVE_WINDOW | cut -f 2" | ||
| #define COMMAND_STR_AWTITLE "xprop -id $(" COMMAND_STR_AWID ") _NET_WM_NAME | cut -d '=' -f 2" | ||
| #define COMMAND_STR_AWPNAME "xprop -id $(" COMMAND_STR_AWID ") WM_CLASS | awk '{print $4}' | sed 's:^.\\(.*\\).$:\\1:'" |
This comment has been minimized.
This comment has been minimized.
kernc
Aug 2, 2016
Owner
Seems like you can use xprop -id 0x59ab7b9 0s '\t$1' WM_CLASS | cut -f2- as bit lighter alternative.
kernc
reviewed
Aug 2, 2016
| @@ -531,7 +611,9 @@ int main(int argc, char **argv) | |||
| } | |||
| } | |||
| } | |||
|
|
|||
|
|
|||
| ////possible conflict if key repeated and program changed??? | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I think there is a user's manual file somewhere in the distribution. Perhaps mention the new switch there as well? Overall, looks good to me. @jzohrab, do you, as the previous most active maintainer, have something to add? |
kernc
reviewed
Aug 2, 2016
|
|
||
| // active window id, title, name | ||
| #define COMMAND_STR_AWID "xprop -root 32x '\\t$0' _NET_ACTIVE_WINDOW | cut -f 2" | ||
| #define COMMAND_STR_AWTITLE "xprop -id $(" COMMAND_STR_AWID ") _NET_WM_NAME | cut -d '=' -f 2" |
This comment has been minimized.
This comment has been minimized.
kernc
Aug 2, 2016
•
Owner
If the window title contains '=', this will include only the portion of the tile up to it. Use cut -d'=' -f2-.
This comment has been minimized.
This comment has been minimized.
|
Hi |
t0mOURCSSn
added some commits
Aug 6, 2016
t0mOURCSSn
reviewed
Aug 6, 2016
| window_id = execute(COMMAND_STR_AWID); | ||
|
|
||
| if (window_id.compare(old_window_id) != 0) { | ||
| cur_process_name = execute(COMMAND_STR_AWPNAME); |
This comment has been minimized.
This comment has been minimized.
t0mOURCSSn
Aug 6, 2016
Author
COMMAND_STR_AWPNAME contains COMMAND_STR_AWID to determine the window id.
Since here we already have the window id, it would be better to change COMMAND_STR_AWPNAME and COMMAND_STR_AWTITLE to use the already determined window_id, maybe by splitting them up?
this way we would use xprop to get the window id only once, instead of 3 times.
t0mOURCSSn
reviewed
Aug 6, 2016
| if (args.flags & FLAG_WINDOW_TITLE) { | ||
| window_id = execute(COMMAND_STR_AWID); | ||
|
|
||
| //// really ugly! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Just to be safe, don't go into replacing xprop calls with Xlib calls. I now think it's better if logkeys doesn't depend on X. |
This comment has been minimized.
This comment has been minimized.
|
I made the changes you suggested in the comments. Apart from the 'really ugly' commented part, I think this might be the final non-X11 version. (unless we find other errors/improvements that is) For the X11 version: While I was able to make the code snippet work in a separate while loop in main(), I was unable to make it work in the default
I just saw your update. How do we proceed? My code is almost finished, should we just keep it in a separate fork? |
This comment has been minimized.
This comment has been minimized.
|
FYI: I did a quick google search and it seems saving clipboard content can only be done with the help of X11. |
This comment has been minimized.
This comment has been minimized.
|
The problem with Xlib is that, unless it was dynamically loaded if present ( Similarly to |
kernc
reviewed
Aug 14, 2016
| @@ -48,10 +48,17 @@ | |||
| #define COMMAND_STR_DUMPKEYS ( EXE_DUMPKEYS " -n | " EXE_GREP " '^\\([[:space:]]shift[[:space:]]\\)*\\([[:space:]]altgr[[:space:]]\\)*keycode'" ) | |||
| #define COMMAND_STR_GET_PID ( (std::string(EXE_PS " ax | " EXE_GREP " '") + program_invocation_name + "' | " EXE_GREP " -v grep").c_str() ) | |||
|
|
|||
| #define COMMAND_STR_DEVICE EXE_GREP " -E 'Handlers|EV' /proc/bus/input/devices | " EXE_GREP " -B1 120013 | " EXE_GREP " -Eo event[0-9]+" | |||
This comment has been minimized.
This comment has been minimized.
kernc
reviewed
Aug 14, 2016
| //// really ugly! | ||
| if (window_id.compare(old_window_id) != 0) { | ||
| process_name = sprintf("xprop -id $(%s) 0s '\\t$1' WM_CLASS | cut -f2-", window_id.c_str()); | ||
| window_title = sprintf("xprop -id $(%s) _NET_WM_NAME | cut -d'=' -f2-", window_id.c_str()); |
This comment has been minimized.
This comment has been minimized.
kernc
Aug 14, 2016
Owner
Perhaps #define these commands with the rest of shell commands defined above?
kernc
reviewed
Aug 14, 2016
| @@ -27,6 +27,7 @@ void usage() | |||
| " --export-keymap=FILE export configured keymap to FILE and exit\n" | |||
| " --no-func-keys log only character keys\n" | |||
| " --no-timestamps don't prepend timestamps to log file lines\n" | |||
| " --window-title add active program window name and window title to log file\n" | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Is there still interest in this feature? |
t0mOURCSSn commentedJul 28, 2016
•
edited
Uploading upload.txt…
@kernc
Hi I implemented a feature to include the program & window name in logkeys' logs.
I would be honored to have my code in your project.
New to git and the whole GitHub forking aspect.
I'll gladly explain in detail the differences.
Attached you will find an example log.
The main changes are:
-added argument "--programinfo"
-the code "on key press (EV_MAKE)" was split into 2 functions, one for newlines and one to encode the scan_codes
Issues/Questions:
Currently using "xprop" to determine the window id and name, maybe there is a better command?