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

Add Programname and Windowname to logs #152

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
31 changes: 14 additions & 17 deletions src/logkeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@

// 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:'"

#define INPUT_EVENT_PATH "/dev/input/" // standard path
#define DEFAULT_LOG_FILE "/var/log/logkeys.log"
Expand All @@ -77,8 +75,8 @@ std::string execute(const char* cmd)
char buffer[128];
std::string result = "";
while(!feof(pipe))
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
pclose(pipe);
return result;
}
Expand Down Expand Up @@ -533,11 +531,11 @@ int main(int argc, char **argv)

fflush(out);

//// programinfo
// programinfo
std::string window_id;
std::string old_window_id;
std::string cur_process_name;
std::string cur_window_name;
std::string process_name;
std::string window_title;
std::string program_info;
bool program_changed = false;

Expand All @@ -560,15 +558,17 @@ int main(int argc, char **argv)
continue;
}

//// 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?
// on processid change, update window-title write '[process name] "window title" > '
if (args.flags & FLAG_WINDOW_TITLE) {
window_id = execute(COMMAND_STR_AWID);
Copy link
Owner

Choose a reason for hiding this comment

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

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?


//// really ugly!
Copy link
Author

Choose a reason for hiding this comment

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

really ugly this part!

if (window_id.compare(old_window_id) != 0) {
cur_process_name = execute(COMMAND_STR_AWPNAME);
cur_window_name = execute(COMMAND_STR_AWTITLE);
program_info = "[" + cur_process_name.erase(cur_process_name.size() - 1) + "] " + cur_window_name.erase(cur_window_name.size() - 1) + " > "; // delete newline (why are newlines)
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());
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps #define these commands with the rest of shell commands defined above?

window_title = execute(window_title.c_str());
process_name = execute(process_name.c_str());
program_info = "[" + process_name.erase(process_name.size() - 1) + "] " + window_title.erase(window_title.size() - 1) + " > "; // delete newline (why are newlines)
program_changed = true;
}
}
Expand Down Expand Up @@ -612,8 +612,6 @@ int main(int argc, char **argv)
}
}

////possible conflict if key repeated and program changed???

// on key repeat ; must check before on key press
if (event.value == EV_REPEAT) {
++count_repeats;
Expand All @@ -630,7 +628,7 @@ int main(int argc, char **argv)

// on key press
if (event.value == EV_MAKE) {
// on ENTER key or Ctrl+C/Ctrl+D event append timestamp and programinfo
// on ENTER key or Ctrl+C/Ctrl+D event append timestamp and window-title
if (scan_code == KEY_ENTER || scan_code == KEY_KPENTER) {
inc_size += newline(out, event, program_changed, program_info);
}
Expand Down Expand Up @@ -661,7 +659,7 @@ int main(int argc, char **argv)
}

// update program id
if (args.flags & FLAG_PROGRAMINFO) {
if (args.flags & FLAG_WINDOW_TITLE) {
old_window_id = window_id;
program_changed = false;
}
Expand Down Expand Up @@ -691,4 +689,3 @@ int main(int argc, char** argv)
{
return logkeys::main(argc, argv);
}