mirror of
https://github.com/rbreaves/kinto.git
synced 2025-08-05 18:38:26 +02:00
- kintox11 updated to support json config files, added support for unlimited app types and keyboard configurations (no longer binary).
This commit is contained in:
Binary file not shown.
16
kintox11/src/kinto.json
Normal file
16
kintox11/src/kinto.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{"config":[{
|
||||||
|
"name":"gui",
|
||||||
|
"run":"setxkbmap -option;xkbcomp -w0 -I$HOME/.xkb ~/.xkb/keymap/kbd.mac.gui $DISPLAY",
|
||||||
|
"appnames":[ "" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"term",
|
||||||
|
"run":"setxkbmap -option",
|
||||||
|
"appnames":[ "Gnome-terminal","konsole","terminator","sakura","guake","tilda","xterm","eterm" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"eosterm",
|
||||||
|
"run":"setxkbmap -option",
|
||||||
|
"appnames":[ "io.elementary.terminal" ]
|
||||||
|
}]
|
||||||
|
}
|
@@ -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 kintox11.c -lX11 -lXmu
|
// gcc kintox11.c -lX11 -lXmu -ljson-c
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
@@ -17,11 +17,20 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <X11/Xlib.h> // `apt-get install libx11-dev`
|
#include <X11/Xlib.h> // `apt-get install libx11-dev`
|
||||||
#include <X11/Xmu/WinUtil.h> // `apt-get install libxmu-dev`
|
#include <X11/Xmu/WinUtil.h> // `apt-get install libxmu-dev`
|
||||||
#define LSIZ 128 // buffer
|
#include <json-c/json.h> // `apt install libjson-c-dev`
|
||||||
#define RSIZ 50 // array size
|
|
||||||
|
|
||||||
Bool xerror = False;
|
Bool xerror = False;
|
||||||
|
|
||||||
|
int in(const char **arr, int len, char *target) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < len; i++) {
|
||||||
|
if(strncmp(arr[i], target, strlen(target)) == 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int strcicmp(char const *a, char const *b)
|
int strcicmp(char const *a, char const *b)
|
||||||
{
|
{
|
||||||
for (;; a++, b++) {
|
for (;; a++, b++) {
|
||||||
@@ -88,20 +97,67 @@ const char * str_window_class(Display* d, Window w, char *prior_app ){
|
|||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
|
|
||||||
char line[RSIZ][LSIZ];
|
FILE *fp;
|
||||||
FILE *fptr = NULL;
|
char buffer[1024];
|
||||||
int i = 0;
|
struct json_object *parsed_json, *config, *config_obj, *config_obj_name, *config_obj_run, *config_obj_appnames, *appnames_obj;
|
||||||
int tot = 0;
|
int arraylen;
|
||||||
|
int appnames_len;
|
||||||
|
int system(const char *command);
|
||||||
|
|
||||||
fptr = fopen("./appnames.csv", "r");
|
size_t i,n;
|
||||||
while(fgets(line[i], LSIZ, fptr))
|
|
||||||
{
|
fp = fopen("kinto.json","r");
|
||||||
line[i][strlen(line[i])] = '\0';
|
fread(buffer, 1024, 1, fp);
|
||||||
if( line[i][strlen(line[i])-1] == '\n' )
|
fclose(fp);
|
||||||
line[i][strlen(line[i])-1] = 0;
|
|
||||||
i++;
|
parsed_json = json_tokener_parse(buffer);
|
||||||
|
|
||||||
|
config = json_object_object_get(parsed_json, "config");
|
||||||
|
|
||||||
|
arraylen = json_object_array_length(config);
|
||||||
|
const char *name_array[arraylen];
|
||||||
|
const char *run_array[arraylen];
|
||||||
|
int appnames_max = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < arraylen; i++) {
|
||||||
|
config_obj = json_object_array_get_idx(config, i);
|
||||||
|
config_obj_appnames = json_object_object_get(config_obj, "appnames");
|
||||||
|
appnames_len = json_object_array_length(config_obj_appnames);
|
||||||
|
if (appnames_len > appnames_max){
|
||||||
|
appnames_max = appnames_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const char *appnames_array[arraylen][appnames_max];
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < arraylen; i++) {
|
||||||
|
config_obj = json_object_array_get_idx(config, i);
|
||||||
|
config_obj_name = json_object_object_get(config_obj, "name");
|
||||||
|
config_obj_run = json_object_object_get(config_obj, "run");
|
||||||
|
name_array[i] = json_object_get_string(config_obj_name);
|
||||||
|
run_array[i] = json_object_get_string(config_obj_run);
|
||||||
|
// printf("%s\n%s\n", json_object_get_string(config_obj_name), json_object_get_string(config_obj_run));
|
||||||
|
|
||||||
|
config_obj_appnames = json_object_object_get(config_obj, "appnames");
|
||||||
|
appnames_len = json_object_array_length(config_obj_appnames);
|
||||||
|
for (n = 0; n < appnames_len; n++) {
|
||||||
|
// printf("name_array[i]: %s\n",name_array[i]);
|
||||||
|
if(!strcicmp(name_array[i], "gui")){
|
||||||
|
appnames_array[i][n] = NULL;
|
||||||
|
// printf("%s i:%ld n:%ld %s\n",name_array[i],i,n,appnames_array[i][n]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
appnames_array[i][n] = json_object_get_string(json_object_array_get_idx(config_obj_appnames, n));
|
||||||
|
// printf("%s i:%ld n:%ld %s\n",name_array[i],i,n,appnames_array[i][n]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(appnames_max > appnames_len){
|
||||||
|
for (n = appnames_len; n < appnames_max; n++){
|
||||||
|
appnames_array[i][n] = NULL;
|
||||||
|
// printf("%s i:%ld n:%ld %s\n",name_array[i],i,n,appnames_array[i][n]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tot = i;
|
|
||||||
|
|
||||||
Display* d;
|
Display* d;
|
||||||
Window w;
|
Window w;
|
||||||
@@ -122,32 +178,52 @@ int main(void){
|
|||||||
// get active window
|
// get active window
|
||||||
w = get_focus_window(d);
|
w = get_focus_window(d);
|
||||||
|
|
||||||
|
int breakouter;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
breakouter = 0;
|
||||||
|
|
||||||
if(strcmp(str_window_class(d, w,prior_app),prior_app)){
|
if(strcmp(str_window_class(d, w,prior_app),prior_app)){
|
||||||
int len = sizeof(line)/sizeof(line[0]);
|
for(i = 0; i < arraylen; ++i){
|
||||||
// printf("length: %d\n",len);
|
if(breakouter == 0){
|
||||||
int i;
|
if(strcmp(name_array[i],"gui")){
|
||||||
for(i = 0; i < len; ++i){
|
for(n = 0; n < appnames_max; ++n){
|
||||||
// printf("i: %d\n",i);
|
if (appnames_array[i][n] != NULL){
|
||||||
// printf(strcicmp(line[i], str_window_class(d, w, prior_app)));
|
// printf("%s\n",appnames_array[i][n]);
|
||||||
if((strcicmp(line[i], str_window_class(d, w,prior_app)) == 0 && (remap_bool == 1 || remap_bool == 2))) {
|
if((strcicmp(appnames_array[i][n], str_window_class(d, w,prior_app)) == 0 && (remap_bool == 1 || remap_bool == 2))) {
|
||||||
// printf("Gotcha!\n");
|
// printf("1st if %s i:%ld n:%ld %s\n",name_array[i],i,n,appnames_array[i][n]);
|
||||||
// printf("%s - prior app %s\n",str_window_class(d, w, prior_app),prior_app);
|
printf("%s\n",name_array[i]);
|
||||||
printf("%s\n","term");
|
system(run_array[i]);
|
||||||
remap_bool = 0;
|
remap_bool = 0;
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
break;
|
breakouter = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if((strcicmp(appnames_array[i][n], str_window_class(d, w,prior_app)) == 0 && remap_bool == 0)){
|
||||||
|
// printf("2nd elseif %s i:%ld n:%ld %s\n",name_array[i],i,n,appnames_array[i][n]);
|
||||||
|
breakouter = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if ((i == arraylen-1 || appnames_array[i][n+1] == NULL) && (remap_bool == 0 || remap_bool == 2)){
|
||||||
|
char *find = "gui";
|
||||||
|
int gui_idx = in(name_array, arraylen, find);
|
||||||
|
|
||||||
|
if(gui_idx >= 0) {
|
||||||
|
printf("%s\n",name_array[gui_idx]);
|
||||||
|
system(run_array[gui_idx]);
|
||||||
|
}
|
||||||
|
// printf("3rd elseif %s i:%ld n:%ld %s\n",name_array[i],i,n,appnames_array[i][n]);
|
||||||
|
remap_bool = 1;
|
||||||
|
fflush(stdout);
|
||||||
|
breakouter = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if((strcicmp(line[i], str_window_class(d, w,prior_app)) == 0 && remap_bool == 0)){
|
else{
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (i == 49 && (remap_bool == 0 || remap_bool == 2)){
|
|
||||||
printf("%s\n","gui");
|
|
||||||
// printf("no match - %s - prior app %s\n",str_window_class(d, w, prior_app),prior_app);
|
|
||||||
remap_bool = 1;
|
|
||||||
fflush(stdout);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user