mirror of
https://github.com/rbreaves/kinto.git
synced 2025-08-02 00:56:39 +02:00
- Improved stability of kintox11, removed unneeded functions
This commit is contained in:
Binary file not shown.
@@ -6,7 +6,7 @@
|
|||||||
http://k-ui.jp/blog/2012/05/07/get-active-window-on-x-window-system/
|
http://k-ui.jp/blog/2012/05/07/get-active-window-on-x-window-system/
|
||||||
*/
|
*/
|
||||||
// To compile
|
// To compile
|
||||||
// gcc active_window.c -lX11 -lXmu
|
// gcc kintox11.c -lX11 -lXmu
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
@@ -61,82 +61,8 @@ Window get_focus_window(Display* d){
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the top window.
|
|
||||||
// a top window have the following specifications.
|
|
||||||
// * the start window is contained the descendent windows.
|
|
||||||
// * the parent window is the root window.
|
|
||||||
Window get_top_window(Display* d, Window start){
|
|
||||||
Window w = start;
|
|
||||||
Window parent = start;
|
|
||||||
Window root = None;
|
|
||||||
Window *children;
|
|
||||||
unsigned int nchildren;
|
|
||||||
Status s;
|
|
||||||
|
|
||||||
while (parent != root) {
|
const char * str_window_class(Display* d, Window w, char *prior_app ){
|
||||||
w = parent;
|
|
||||||
s = XQueryTree(d, w, &root, &parent, &children, &nchildren); // see man
|
|
||||||
|
|
||||||
if (s)
|
|
||||||
XFree(children);
|
|
||||||
|
|
||||||
if(xerror){
|
|
||||||
printf("failed to get top window\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
// search a named window (that has a WM_STATE prop)
|
|
||||||
// on the descendent windows of the argment Window.
|
|
||||||
Window get_named_window(Display* d, Window start){
|
|
||||||
Window w;
|
|
||||||
w = XmuClientWindow(d, start); // see man
|
|
||||||
if(w == start)
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
// (XFetchName cannot get a name with multi-byte chars)
|
|
||||||
void print_window_name(Display* d, Window w){
|
|
||||||
XTextProperty prop;
|
|
||||||
Status s;
|
|
||||||
|
|
||||||
s = XGetWMName(d, w, &prop); // see man
|
|
||||||
if(!xerror && s){
|
|
||||||
int count = 0, result;
|
|
||||||
char **list = NULL;
|
|
||||||
result = XmbTextPropertyToTextList(d, &prop, &list, &count); // see man
|
|
||||||
if(result == Success){
|
|
||||||
printf("\t%s\n", list[0]);
|
|
||||||
}else{
|
|
||||||
// printf("ERROR: XmbTextPropertyToTextList\n");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
// printf("ERROR: XGetWMName\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_window_class(Display* d, Window w){
|
|
||||||
Status s;
|
|
||||||
XClassHint* class;
|
|
||||||
|
|
||||||
class = XAllocClassHint(); // see man
|
|
||||||
if(xerror){
|
|
||||||
// printf("ERROR: XAllocClassHint\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
s = XGetClassHint(d, w, class); // see man
|
|
||||||
if(xerror || s){
|
|
||||||
// printf("\tname: %s\n\tclass: %s\n", class->res_name, class->res_class);
|
|
||||||
printf("%s\n", class->res_class);
|
|
||||||
}else{
|
|
||||||
printf("ERROR: XGetClassHint\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * str_window_class(Display* d, Window w){
|
|
||||||
Status s;
|
Status s;
|
||||||
XClassHint* class;
|
XClassHint* class;
|
||||||
|
|
||||||
@@ -153,17 +79,13 @@ const char * str_window_class(Display* d, Window w){
|
|||||||
// printf("\tname: %s\n\tclass: %s\n", class->res_name, class->res_class);
|
// printf("\tname: %s\n\tclass: %s\n", class->res_name, class->res_class);
|
||||||
return app_class;
|
return app_class;
|
||||||
}else{
|
}else{
|
||||||
char * error_msg;
|
// char * error_msg;
|
||||||
error_msg = malloc(sizeof(char)*50);
|
// error_msg = malloc(sizeof(char)*50);
|
||||||
strcpy(error_msg, "ERROR: XGetClassHint");
|
// strcpy(error_msg, "ERROR: XGetClassHint");
|
||||||
return error_msg;
|
return prior_app;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_window_info(Display* d, Window w){
|
|
||||||
print_window_class(d, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
|
|
||||||
char line[RSIZ][LSIZ];
|
char line[RSIZ][LSIZ];
|
||||||
@@ -181,13 +103,6 @@ int main(void){
|
|||||||
}
|
}
|
||||||
tot = i;
|
tot = i;
|
||||||
|
|
||||||
// printf("\n The content of the file %s are : \n","./appnames.csv");
|
|
||||||
// for(i = 0; i < tot; ++i)
|
|
||||||
// {
|
|
||||||
// printf("%s\n", line[i]);
|
|
||||||
// }
|
|
||||||
// printf("\n");
|
|
||||||
|
|
||||||
Display* d;
|
Display* d;
|
||||||
Window w;
|
Window w;
|
||||||
|
|
||||||
@@ -206,46 +121,42 @@ int main(void){
|
|||||||
|
|
||||||
// get active window
|
// get active window
|
||||||
w = get_focus_window(d);
|
w = get_focus_window(d);
|
||||||
w = get_top_window(d, w);
|
|
||||||
w = get_named_window(d, w);
|
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(strcmp(str_window_class(d, w),prior_app)){
|
if(strcmp(str_window_class(d, w,prior_app),prior_app)){
|
||||||
int len = sizeof(line)/sizeof(line[0]);
|
int len = sizeof(line)/sizeof(line[0]);
|
||||||
// printf("length: %d\n",len);
|
// printf("length: %d\n",len);
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < len; ++i){
|
for(i = 0; i < len; ++i){
|
||||||
// printf("i: %d\n",i);
|
// printf("i: %d\n",i);
|
||||||
// printf(strcicmp(line[i], str_window_class(d, w)));
|
// printf(strcicmp(line[i], str_window_class(d, w, prior_app)));
|
||||||
if((strcicmp(line[i], str_window_class(d, w)) == 0 && (remap_bool == 1 || remap_bool == 2))) {
|
if((strcicmp(line[i], str_window_class(d, w,prior_app)) == 0 && (remap_bool == 1 || remap_bool == 2))) {
|
||||||
// printf("Gotcha!\n");
|
// printf("Gotcha!\n");
|
||||||
// printf("%s - prior app %s\n",str_window_class(d, w),prior_app);
|
// printf("%s - prior app %s\n",str_window_class(d, w, prior_app),prior_app);
|
||||||
printf("%s\n","term");
|
printf("%s\n","term");
|
||||||
remap_bool = 0;
|
remap_bool = 0;
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if((strcicmp(line[i], str_window_class(d, w)) == 0 && remap_bool == 0)){
|
else if((strcicmp(line[i], str_window_class(d, w,prior_app)) == 0 && remap_bool == 0)){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (i == 49 && (remap_bool == 0 || remap_bool == 2)){
|
else if (i == 49 && (remap_bool == 0 || remap_bool == 2)){
|
||||||
printf("%s\n","gui");
|
printf("%s\n","gui");
|
||||||
// printf("no match - %s - prior app %s\n",str_window_class(d, w),prior_app);
|
// printf("no match - %s - prior app %s\n",str_window_class(d, w, prior_app),prior_app);
|
||||||
remap_bool = 1;
|
remap_bool = 1;
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcpy(prior_app,str_window_class(d, w));
|
strcpy(prior_app,str_window_class(d, w, prior_app));
|
||||||
|
|
||||||
XEvent e;
|
XEvent e;
|
||||||
XNextEvent(d, &e);
|
XNextEvent(d, &e);
|
||||||
// get active window
|
|
||||||
w = get_focus_window(d);
|
w = get_focus_window(d);
|
||||||
w = get_top_window(d, w);
|
|
||||||
w = get_named_window(d, w);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user