xaizek / euclid-wm (License: BSD 3-Clause) (since 2018-12-07)
A minimalist, tiling window manager for X11 that seeks to allow easy management of numerous windows entirely from the keyboard.
Commit 11d9f5c1817aeb825fcd82f522820a5240776d5d

commiting initial changes to euclid-wm.c
Author: wmdiem
Author date (UTC): 2010-08-01 15:02
Committer name: wmdiem
Committer date (UTC): 2010-08-01 15:02
Parent(s): 8c8480419d3ef363c1666b0162b483f9d4c27ec0
Signing key:
Tree: 15ef1f9c079f832a0628f9a63a69ebf869154249
File Lines added Lines deleted
euclid-wm.c 505 443
File euclid-wm.c changed (mode: 100644) (index 5e4f920..b2a4989)
... ... Thus the one or more of the following notices may apply to some sections:
76 76 * DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
77 77
78 78 */ */
79
80
81 79 #include <stdio.h> #include <stdio.h>
82 80 #include <stdlib.h> #include <stdlib.h>
83 81 #include <unistd.h> #include <unistd.h>
 
... ... Thus the one or more of the following notices may apply to some sections:
88 86 #include <X11/Xutil.h> #include <X11/Xutil.h>
89 87 #include <X11/Xatom.h> #include <X11/Xatom.h>
90 88 #include <errno.h> #include <errno.h>
89 #include <X11/extensions/Xinerama.h>
91 90
92 91 #define BINDINGS 62 #define BINDINGS 62
93 92 /*BASIC VARIABLE TYPES*/ /*BASIC VARIABLE TYPES*/
 
... ... Thus the one or more of the following notices may apply to some sections:
106 105 */ */
107 106
108 107
108 struct screen {
109 struct screen *next;
110 struct view *v;
111 Window stackid;
112 int x;
113 int y;
114 unsigned int w;
115 unsigned int h;
116 };
109 117
110 118 struct view { struct view {
111 119 struct view *next; struct view *next;
 
... ... struct binding {
162 170 */ */
163 171
164 172 struct view *fv = NULL; //first view struct view *fv = NULL; //first view
165 struct view *cv = NULL; //current view
173 //struct view *cs->v = NULL; //current view
174 struct screen *cs = NULL;
175 struct screen *firstscreen = NULL;
166 176 struct win *first_win = NULL; struct win *first_win = NULL;
167 177
168 unsigned int scrn_w = 1026;
169 unsigned int scrn_h = 860;
178 //unsigned int cs->w = 1026;
179 //unsigned int cs->h = 860;
170 180 unsigned int mod = Mod1Mask; unsigned int mod = Mod1Mask;
171 181 unsigned int mods = Mod1Mask | ShiftMask; unsigned int mods = Mod1Mask | ShiftMask;
172 182 bool sloppy_focus = true; bool sloppy_focus = true;
 
... ... unsigned long stack_unfocus_pix;
181 191 GC focus_gc = NULL; GC focus_gc = NULL;
182 192 GC unfocus_gc = NULL; GC unfocus_gc = NULL;
183 193 bool gxerror = false; bool gxerror = false;
184 Window stackid;
194 //Window cs->stackid;
185 195 Atom wm_del_win; Atom wm_del_win;
186 196 Atom wm_take_focus; Atom wm_take_focus;
187 197 Atom wm_prot; Atom wm_prot;
 
... ... void load_conf() {
362 372 }; };
363 373 strcat(confdir,"/euclid-wm"); strcat(confdir,"/euclid-wm");
364 374 strcpy(rcfile,confdir); strcpy(rcfile,confdir);
365 //why do we have an & ?
366 375 strcat(rcfile,"/euclidrc"); strcat(rcfile,"/euclidrc");
367 376 spawn(rcfile); spawn(rcfile);
368 377
 
... ... struct view * make_view() {
658 667 ptr->ft->next = NULL; ptr->ft->next = NULL;
659 668 ptr->ft->prev = NULL; ptr->ft->prev = NULL;
660 669 ptr->ft->c = NULL; ptr->ft->c = NULL;
661 ptr->ft->size = scrn_w;
670 ptr->ft->size = cs->w;
662 671 ptr->orientv = true; ptr->orientv = true;
663 672 ptr->stack = NULL; ptr->stack = NULL;
664 673 ptr->showstack = true; ptr->showstack = true;
 
... ... struct view * make_view() {
666 675 return ptr; return ptr;
667 676 } }
668 677
678 void addscreen(short h, short w, short x, short y, short n) {
679
680 struct screen *new = (struct screen * ) malloc (sizeof(struct screen));
681 //set the pointers
682
683
684 new->next = NULL;
685 if (firstscreen == NULL) {
686 //set it as first screen
687 firstscreen = new;
688 cs = new;
689 } else {
690 struct screen *s = firstscreen;
691 while (s->next != NULL) {
692 s = s->next;
693 };
694 s->next = new;
695 }
696 //define its geomentry
697 new->h = h;
698 new->w = w;
699 new->x = x;
700 new->y = y;
701 //make it a view
702 new->v = make_view();
703 //set view idx
704 new->v->idx = n;
705 //make it a stack window
706 new->stackid = XCreateSimpleWindow(dpy,root,0,((h - 15) + y),(w + x),15,1,stack_unfocus_pix,stack_background_pix);
707 XSetWindowAttributes att;
708 att.override_redirect = true;
709 XChangeWindowAttributes(dpy,cs->stackid,CWOverrideRedirect,&att);
710 XMapWindow(dpy,new->stackid);
711 XSync(dpy,False);
712 };
713
669 714 void remove_cont(struct cont *c) { void remove_cont(struct cont *c) {
670 715 //reset focus if necessary //reset focus if necessary
671 716 if (c->next != NULL) { if (c->next != NULL) {
 
... ... void forget_win (Window id) {
809 854 free(c); free(c);
810 855 } else { } else {
811 856 //its the first track, but there is a next //its the first track, but there is a next
812 cv->ft = c->track->next;
857 cs->v->ft = c->track->next;
813 858 c->track->next->prev = NULL; c->track->next->prev = NULL;
814 859 free (c->track); free (c->track);
815 860 free (c); free (c);
 
... ... void add_client_to_view (struct win *p, struct view *v) {
917 962 c->track = v->ft; c->track = v->ft;
918 963 v->ft->c = c; v->ft->c = c;
919 964 if (v->orientv == true) { if (v->orientv == true) {
920 c->size = scrn_h;
965 c->size = cs->h;
921 966 } else { } else {
922 c->size = scrn_w;
967 c->size = cs->w;
923 968 }; };
924 969 }; };
925 970 c->win = p; c->win = p;
 
... ... void add_client_to_view (struct win *p, struct view *v) {
928 973
929 974 void move_to_stack(struct cont *c) { void move_to_stack(struct cont *c) {
930 975 struct stack_item *s = (struct stack_item *) malloc (sizeof(struct stack_item)); struct stack_item *s = (struct stack_item *) malloc (sizeof(struct stack_item));
931 struct stack_item *p = cv->sfocus;
976 struct stack_item *p = cs->v->sfocus;
932 977 s->win = c->win; s->win = c->win;
933 978 if (p != NULL) { if (p != NULL) {
934 979 s->next = p->next; s->next = p->next;
 
... ... void move_to_stack(struct cont *c) {
937 982 }; };
938 983 p->next = s; p->next = s;
939 984 } else { } else {
940 cv->stack = s;
985 cs->v->stack = s;
941 986 s->next = NULL; s->next = NULL;
942 987 }; };
943 988 s->prev = p; s->prev = p;
944 cv->sfocus = s;
989 cs->v->sfocus = s;
945 990 remove_cont(c); remove_cont(c);
946 991 } }
947 992
948 993 void move_to_main() { void move_to_main() {
949 994 //just add whatever has stack focus to the layout //just add whatever has stack focus to the layout
950 if (cv->sfocus == NULL) {return;};
951 add_client_to_view(cv->sfocus->win, cv);
995 if (cs->v->sfocus == NULL) {return;};
996 add_client_to_view(cs->v->sfocus->win, cs->v);
952 997 //remove it from the stack: //remove it from the stack:
953 struct stack_item *p = cv->sfocus;
998 struct stack_item *p = cs->v->sfocus;
954 999 //reset sfocus //reset sfocus
955 cv->sfocus = NULL;
1000 cs->v->sfocus = NULL;
956 1001 if (p->prev != NULL) { if (p->prev != NULL) {
957 cv->sfocus = p->prev;
1002 cs->v->sfocus = p->prev;
958 1003 p->prev->next = p->next; p->prev->next = p->next;
959 1004 }; };
960 1005 if (p->next != NULL) { if (p->next != NULL) {
961 1006 p->next->prev = p->prev; p->next->prev = p->prev;
962 if (cv->sfocus == NULL) {
963 cv->sfocus = p->next;
964 cv->stack = p->next;
1007 if (cs->v->sfocus == NULL) {
1008 cs->v->sfocus = p->next;
1009 cs->v->stack = p->next;
965 1010 }; };
966 1011 }; };
967 if (cv->sfocus == NULL) {
968 cv->stack = NULL;
1012 if (cs->v->sfocus == NULL) {
1013 cs->v->stack = NULL;
969 1014 }; };
970 1015 free(p); free(p);
971 1016 } }
972 1017
973 1018 void shift_stack_focus (bool dir) { void shift_stack_focus (bool dir) {
974 1019 //true up, false, down //true up, false, down
975 if (cv->sfocus == NULL) {return;};
976 if (dir && cv->sfocus->prev != NULL) {
977 cv->sfocus = cv->sfocus->prev;
978 } else if (!dir && cv->sfocus->next != NULL) {
979 cv->sfocus = cv->sfocus->next;
1020 if (cs->v->sfocus == NULL) {return;};
1021 if (dir && cs->v->sfocus->prev != NULL) {
1022 cs->v->sfocus = cs->v->sfocus->prev;
1023 } else if (!dir && cs->v->sfocus->next != NULL) {
1024 cs->v->sfocus = cs->v->sfocus->next;
980 1025 }; };
981 1026 } }
982 1027
 
... ... short int convert_to_internal_dir(short int dir) {/*four possibilities:
1020 1065 * 3) we are moving down accross tracks * 3) we are moving down accross tracks
1021 1066 * 4) we are moving up accross tracks * 4) we are moving up accross tracks
1022 1067 */ */
1023 if (cv->orientv == true) {
1068 if (cs->v->orientv == true) {
1024 1069 short swp[] = {0,2,3,1,4}; short swp[] = {0,2,3,1,4};
1025 1070 dir = swp[dir]; dir = swp[dir];
1026 1071 } else { } else {
 
... ... short int convert_to_internal_dir(short int dir) {/*four possibilities:
1030 1075 return dir; return dir;
1031 1076 } }
1032 1077 void shift_window(short int dir) { void shift_window(short int dir) {
1033 if (cv->mfocus == NULL) {
1078 if (cs->v->mfocus == NULL) {
1034 1079 return; return;
1035 1080 }; };
1036 1081 dir = convert_to_internal_dir(dir); dir = convert_to_internal_dir(dir);
1037 if (dir == 1 && cv->mfocus->next != NULL) { //down in the track;
1082 if (dir == 1 && cs->v->mfocus->next != NULL) { //down in the track;
1038 1083 //get a direct reference to all four nodes //get a direct reference to all four nodes
1039 1084 //make sure that we are also updating track->c if necessary //make sure that we are also updating track->c if necessary
1040 1085 struct cont *tmpa; struct cont *tmpa;
1041 1086 struct cont *tmpb; struct cont *tmpb;
1042 1087 struct cont *tmpc; struct cont *tmpc;
1043 1088 struct cont *tmpd; struct cont *tmpd;
1044 tmpa = cv->mfocus->prev;
1045 tmpb = cv->mfocus;
1046 tmpc = cv->mfocus->next;
1047 if (cv->mfocus->next != NULL) {
1048 tmpd = cv->mfocus->next->next;
1089 tmpa = cs->v->mfocus->prev;
1090 tmpb = cs->v->mfocus;
1091 tmpc = cs->v->mfocus->next;
1092 if (cs->v->mfocus->next != NULL) {
1093 tmpd = cs->v->mfocus->next->next;
1049 1094 } else {tmpd = NULL;}; } else {tmpd = NULL;};
1050 1095 if (tmpa != NULL) { if (tmpa != NULL) {
1051 1096 tmpa->next = tmpc; tmpa->next = tmpc;
1052 1097 } else { //a is null, b is track->c } else { //a is null, b is track->c
1053 cv->mfocus->track->c = tmpc;
1098 cs->v->mfocus->track->c = tmpc;
1054 1099 }; };
1055 1100 if (tmpd != NULL) { if (tmpd != NULL) {
1056 1101 tmpd->prev = tmpb; tmpd->prev = tmpb;
 
... ... void shift_window(short int dir) {
1061 1106 }; };
1062 1107 tmpb->prev = tmpc; tmpb->prev = tmpc;
1063 1108 tmpb->next = tmpd; tmpb->next = tmpd;
1064 } else if (dir == 2 && cv->mfocus->prev != NULL) {
1109 } else if (dir == 2 && cs->v->mfocus->prev != NULL) {
1065 1110 struct cont *tmpa; struct cont *tmpa;
1066 1111 struct cont *tmpb; struct cont *tmpb;
1067 1112 struct cont *tmpc; struct cont *tmpc;
1068 1113 struct cont *tmpd; struct cont *tmpd;
1069 if (cv->mfocus->prev != NULL) {
1070 tmpa = cv->mfocus->prev->prev;
1114 if (cs->v->mfocus->prev != NULL) {
1115 tmpa = cs->v->mfocus->prev->prev;
1071 1116 } else { } else {
1072 1117 tmpa = NULL; tmpa = NULL;
1073 1118 }; };
1074 tmpb = cv->mfocus->prev;
1075 tmpc = cv->mfocus;
1076 tmpd = cv->mfocus->next;
1119 tmpb = cs->v->mfocus->prev;
1120 tmpc = cs->v->mfocus;
1121 tmpd = cs->v->mfocus->next;
1077 1122 if (tmpa != NULL) { if (tmpa != NULL) {
1078 1123 tmpa->next = tmpc; tmpa->next = tmpc;
1079 1124 }; };
1080 if (cv->mfocus->track->c == tmpb) {
1081 cv->mfocus->track->c = tmpc;
1125 if (cs->v->mfocus->track->c == tmpb) {
1126 cs->v->mfocus->track->c = tmpc;
1082 1127 }; };
1083 1128 if (tmpb != NULL) { if (tmpb != NULL) {
1084 1129 tmpb->prev = tmpc; tmpb->prev = tmpc;
 
... ... void shift_window(short int dir) {
1091 1136 tmpc->next = tmpb; tmpc->next = tmpb;
1092 1137 } else if (dir == 3) { } else if (dir == 3) {
1093 1138 //check for track->next //check for track->next
1094 if (cv->mfocus->track->next != NULL) {
1139 if (cs->v->mfocus->track->next != NULL) {
1095 1140 //find position in it //find position in it
1096 1141 //find the midpoint of the current cont //find the midpoint of the current cont
1097 1142 struct cont *p; struct cont *p;
1098 p = cv->mfocus->prev;
1143 p = cs->v->mfocus->prev;
1099 1144 int s = 0; int s = 0;
1100 1145 int t = 0; int t = 0;
1101 1146 while (p != NULL) { while (p != NULL) {
1102 1147 s += p->size; s += p->size;
1103 1148 p = p->prev; p = p->prev;
1104 1149 }; };
1105 s += (cv->mfocus->size / 2);
1106 p = cv->mfocus->track->next->c;
1150 s += (cs->v->mfocus->size / 2);
1151 p = cs->v->mfocus->track->next->c;
1107 1152 while (p->next != NULL) { while (p->next != NULL) {
1108 1153 t += p->size; t += p->size;
1109 1154 if (t >= s) {break;}; if (t >= s) {break;};
1110 1155 p = p->next; p = p->next;
1111 1156 }; };
1112 1157 if (p != NULL) {//it never should if (p != NULL) {//it never should
1113 if (cv->mfocus->prev != NULL) {
1114 cv->mfocus->prev->next = cv->mfocus->next;
1158 if (cs->v->mfocus->prev != NULL) {
1159 cs->v->mfocus->prev->next = cs->v->mfocus->next;
1115 1160 } else { //it's first } else { //it's first
1116 if (cv->mfocus->next != NULL) {
1117 cv->mfocus->track->c = cv->mfocus->next;
1161 if (cs->v->mfocus->next != NULL) {
1162 cs->v->mfocus->track->c = cs->v->mfocus->next;
1118 1163 } else { } else {
1119 1164 //only one in the track //only one in the track
1120 1165 //remove the old track //remove the old track
1121 if (cv->ft == cv->mfocus->track) {
1122 cv->ft = p->track;
1166 if (cs->v->ft == cs->v->mfocus->track) {
1167 cs->v->ft = p->track;
1123 1168 } else { } else {
1124 cv->mfocus->track->prev->next = p->track;
1169 cs->v->mfocus->track->prev->next = p->track;
1125 1170 }; };
1126 p->track->prev = cv->mfocus->track->prev;
1127 free(cv->mfocus->track);
1171 p->track->prev = cs->v->mfocus->track->prev;
1172 free(cs->v->mfocus->track);
1128 1173 }; };
1129 1174 }; };
1130 if (cv->mfocus->next != NULL) {
1131 cv->mfocus->next->prev = cv->mfocus->prev;
1175 if (cs->v->mfocus->next != NULL) {
1176 cs->v->mfocus->next->prev = cs->v->mfocus->prev;
1132 1177 }; };
1133 1178 //put it behind p //put it behind p
1134 1179 struct cont *b = p->next; struct cont *b = p->next;
1135 1180 if (b != NULL) { if (b != NULL) {
1136 b->prev = cv->mfocus;
1181 b->prev = cs->v->mfocus;
1137 1182 }; };
1138 p->next = cv->mfocus;
1139 cv->mfocus->prev = p;
1140 cv->mfocus->next = b;
1141 cv->mfocus->track = p->track;
1183 p->next = cs->v->mfocus;
1184 cs->v->mfocus->prev = p;
1185 cs->v->mfocus->next = b;
1186 cs->v->mfocus->track = p->track;
1142 1187 }; };
1143 1188 }else{ //make a track for it }else{ //make a track for it
1144 if (cv->mfocus->track->c == cv->mfocus) {
1145 if (cv->mfocus->next != NULL) {
1146 cv->mfocus->track->c = cv->mfocus->next;
1147 } else if (cv->mfocus->prev != NULL) {
1148 cv->mfocus->track->c = cv->mfocus->prev;
1189 if (cs->v->mfocus->track->c == cs->v->mfocus) {
1190 if (cs->v->mfocus->next != NULL) {
1191 cs->v->mfocus->track->c = cs->v->mfocus->next;
1192 } else if (cs->v->mfocus->prev != NULL) {
1193 cs->v->mfocus->track->c = cs->v->mfocus->prev;
1149 1194 } else { } else {
1150 1195 return; //premature return, because movign the window that direction doesn't make any sense return; //premature return, because movign the window that direction doesn't make any sense
1151 1196 }; };
1152 1197 }; };
1153 1198 struct track *ptr = (struct track *) malloc (sizeof(struct track)); struct track *ptr = (struct track *) malloc (sizeof(struct track));
1154 cv->mfocus->track->next = ptr;
1199 cs->v->mfocus->track->next = ptr;
1155 1200 //update all the other links //update all the other links
1156 ptr->view = cv;
1201 ptr->view = cs->v;
1157 1202 ptr->next = NULL; ptr->next = NULL;
1158 ptr->prev = cv->mfocus->track;
1159 ptr->c = cv->mfocus;
1160 ptr->size = cv->mfocus->track->size;
1161 cv->mfocus->track = ptr;
1203 ptr->prev = cs->v->mfocus->track;
1204 ptr->c = cs->v->mfocus;
1205 ptr->size = cs->v->mfocus->track->size;
1206 cs->v->mfocus->track = ptr;
1162 1207 //patch up the hole in mfocus->track //patch up the hole in mfocus->track
1163 if (cv->mfocus->prev != NULL)
1164 cv->mfocus->prev->next = cv->mfocus->next;
1165 if (cv->mfocus->next != NULL)
1166 cv->mfocus->next->prev = cv->mfocus->prev;
1167 cv->mfocus->next = NULL;
1168 cv->mfocus->prev = NULL;
1208 if (cs->v->mfocus->prev != NULL)
1209 cs->v->mfocus->prev->next = cs->v->mfocus->next;
1210 if (cs->v->mfocus->next != NULL)
1211 cs->v->mfocus->next->prev = cs->v->mfocus->prev;
1212 cs->v->mfocus->next = NULL;
1213 cs->v->mfocus->prev = NULL;
1169 1214 }; };
1170 1215 } else if (dir == 4) { //4 } else if (dir == 4) { //4
1171 if (cv->mfocus->track->prev != NULL) {
1216 if (cs->v->mfocus->track->prev != NULL) {
1172 1217 //find position in it //find position in it
1173 1218 //find the midpoint of the current cont //find the midpoint of the current cont
1174 1219 struct cont *p; struct cont *p;
1175 p = cv->mfocus->prev;
1220 p = cs->v->mfocus->prev;
1176 1221 int s = 0; int s = 0;
1177 1222 int t = 0; int t = 0;
1178 1223 while (p != NULL) { while (p != NULL) {
1179 1224 s += p->size; s += p->size;
1180 1225 p = p->prev; p = p->prev;
1181 1226 }; };
1182 s += (cv->mfocus->size / 2);
1183 p = cv->mfocus->track->prev->c;
1227 s += (cs->v->mfocus->size / 2);
1228 p = cs->v->mfocus->track->prev->c;
1184 1229 while (p->next != NULL) { while (p->next != NULL) {
1185 1230 t += p->size; t += p->size;
1186 1231 if (t >= s) {break;}; if (t >= s) {break;};
1187 1232 p = p->next; p = p->next;
1188 1233 }; };
1189 1234 if (p != NULL) {//it never should if (p != NULL) {//it never should
1190 if (cv->mfocus->prev != NULL) {
1191 cv->mfocus->prev->next = cv->mfocus->next;
1235 if (cs->v->mfocus->prev != NULL) {
1236 cs->v->mfocus->prev->next = cs->v->mfocus->next;
1192 1237 } else { //it's first in the track } else { //it's first in the track
1193 if (cv->mfocus->next != NULL) {
1194 cv->mfocus->track->c = cv->mfocus->next;
1238 if (cs->v->mfocus->next != NULL) {
1239 cs->v->mfocus->track->c = cs->v->mfocus->next;
1195 1240 } else { } else {
1196 1241 //only one in the track //only one in the track
1197 1242 //remove the old track //remove the old track
1198 if (cv->mfocus->track->next != NULL) {
1199 cv->mfocus->track->next->prev = p->track;
1243 if (cs->v->mfocus->track->next != NULL) {
1244 cs->v->mfocus->track->next->prev = p->track;
1200 1245 }; };
1201 p->track->next = cv->mfocus->track->next;
1202 free(cv->mfocus->track);
1246 p->track->next = cs->v->mfocus->track->next;
1247 free(cs->v->mfocus->track);
1203 1248 }; };
1204 1249 }; };
1205 if (cv->mfocus->next != NULL) {
1206 cv->mfocus->next->prev = cv->mfocus->prev;
1250 if (cs->v->mfocus->next != NULL) {
1251 cs->v->mfocus->next->prev = cs->v->mfocus->prev;
1207 1252 }; };
1208 1253 //put it behind p //put it behind p
1209 1254 struct cont *b = p->next; struct cont *b = p->next;
1210 1255 if (b != NULL) { if (b != NULL) {
1211 b->prev = cv->mfocus;
1256 b->prev = cs->v->mfocus;
1212 1257 }; };
1213 p->next = cv->mfocus;
1214 cv->mfocus->prev = p;
1215 cv->mfocus->next = b;
1216 cv->mfocus->track = p->track;
1258 p->next = cs->v->mfocus;
1259 cs->v->mfocus->prev = p;
1260 cs->v->mfocus->next = b;
1261 cs->v->mfocus->track = p->track;
1217 1262 }; };
1218 1263 }else{ //make a track for it }else{ //make a track for it
1219 if (cv->mfocus->track->c == cv->mfocus) {
1220 if (cv->mfocus->next != NULL) {
1221 cv->mfocus->track->c = cv->mfocus->next;
1222 } else if (cv->mfocus->prev != NULL) {
1223 cv->mfocus->track->c = cv->mfocus->prev;
1264 if (cs->v->mfocus->track->c == cs->v->mfocus) {
1265 if (cs->v->mfocus->next != NULL) {
1266 cs->v->mfocus->track->c = cs->v->mfocus->next;
1267 } else if (cs->v->mfocus->prev != NULL) {
1268 cs->v->mfocus->track->c = cs->v->mfocus->prev;
1224 1269 } else { } else {
1225 1270 return; //premature return, because movign the window that direction doesn't make any sense return; //premature return, because movign the window that direction doesn't make any sense
1226 1271 }; };
1227 1272 }; };
1228 1273 struct track *ptr = (struct track *) malloc (sizeof(struct track)); struct track *ptr = (struct track *) malloc (sizeof(struct track));
1229 cv->mfocus->track->prev = ptr;
1230 cv->ft = ptr;
1274 cs->v->mfocus->track->prev = ptr;
1275 cs->v->ft = ptr;
1231 1276 //update all the other links //update all the other links
1232 ptr->view = cv;
1233 ptr->next = cv->mfocus->track;
1277 ptr->view = cs->v;
1278 ptr->next = cs->v->mfocus->track;
1234 1279 ptr->prev = NULL; ptr->prev = NULL;
1235 ptr->c = cv->mfocus;
1236 ptr->size = cv->mfocus->track->size;
1237 cv->mfocus->track = ptr;
1280 ptr->c = cs->v->mfocus;
1281 ptr->size = cs->v->mfocus->track->size;
1282 cs->v->mfocus->track = ptr;
1238 1283 //patch up the hole in mfocus->track //patch up the hole in mfocus->track
1239 if (cv->mfocus->prev != NULL)
1240 cv->mfocus->prev->next = cv->mfocus->next;
1241 if (cv->mfocus->next != NULL)
1242 cv->mfocus->next->prev = cv->mfocus->prev;
1243 cv->mfocus->prev = NULL;
1244 cv->mfocus->next = NULL;
1284 if (cs->v->mfocus->prev != NULL)
1285 cs->v->mfocus->prev->next = cs->v->mfocus->next;
1286 if (cs->v->mfocus->next != NULL)
1287 cs->v->mfocus->next->prev = cs->v->mfocus->prev;
1288 cs->v->mfocus->prev = NULL;
1289 cs->v->mfocus->next = NULL;
1245 1290 }; };
1246 1291 }; };
1247 if (cv->mfocus->prev != NULL) {
1248 cv->mfocus->size = cv->mfocus->prev->size;
1249 } else if (cv->mfocus->next != NULL) {
1250 cv->mfocus->size = cv->mfocus->next->size;
1292 if (cs->v->mfocus->prev != NULL) {
1293 cs->v->mfocus->size = cs->v->mfocus->prev->size;
1294 } else if (cs->v->mfocus->next != NULL) {
1295 cs->v->mfocus->size = cs->v->mfocus->next->size;
1251 1296 }; };
1252 1297 } }
1253 1298
1254 1299 void shift_main_focus(short int dir) { void shift_main_focus(short int dir) {
1255 if (cv->mfocus == NULL) {return;};
1300 if (cs->v->mfocus == NULL) {return;};
1256 1301 dir = convert_to_internal_dir(dir); dir = convert_to_internal_dir(dir);
1257 1302 if (dir == 1) { if (dir == 1) {
1258 if (cv->fs == false) {
1259 if (cv->mfocus->next != NULL) {
1260 cv->mfocus = cv->mfocus->next;
1303 if (cs->v->fs == false) {
1304 if (cs->v->mfocus->next != NULL) {
1305 cs->v->mfocus = cs->v->mfocus->next;
1261 1306 }; };
1262 1307 } else { } else {
1263 if (cv->mfocus->next != NULL) {
1264 cv->mfocus = cv->mfocus->next;
1265 } else if (cv->mfocus->track->next != NULL) {
1266 cv->mfocus = cv->mfocus->track->next->c;
1308 if (cs->v->mfocus->next != NULL) {
1309 cs->v->mfocus = cs->v->mfocus->next;
1310 } else if (cs->v->mfocus->track->next != NULL) {
1311 cs->v->mfocus = cs->v->mfocus->track->next->c;
1267 1312 }; };
1268 1313 }; };
1269 1314 } else if (dir == 2) { } else if (dir == 2) {
1270 if (cv->fs == false) {
1271 if (cv->mfocus->prev != NULL) {
1272 cv->mfocus = cv->mfocus->prev;
1315 if (cs->v->fs == false) {
1316 if (cs->v->mfocus->prev != NULL) {
1317 cs->v->mfocus = cs->v->mfocus->prev;
1273 1318 }; };
1274 1319 } else { } else {
1275 if (cv->mfocus->prev != NULL) {
1276 cv->mfocus = cv->mfocus->prev;
1277 } else if (cv->mfocus->track->prev != NULL ) {
1278 cv->mfocus = cv->mfocus->track->prev->c;
1320 if (cs->v->mfocus->prev != NULL) {
1321 cs->v->mfocus = cs->v->mfocus->prev;
1322 } else if (cs->v->mfocus->track->prev != NULL ) {
1323 cs->v->mfocus = cs->v->mfocus->track->prev->c;
1279 1324 }; };
1280 1325 }; };
1281 } else if (dir == 3 && cv->mfocus->track->next != NULL) {
1282 if (cv->fs == false) {
1326 } else if (dir == 3 && cs->v->mfocus->track->next != NULL) {
1327 if (cs->v->fs == false) {
1283 1328 struct cont *p; struct cont *p;
1284 p = cv->mfocus->prev;
1329 p = cs->v->mfocus->prev;
1285 1330 int s = 0; int s = 0;
1286 1331 int t = 0; int t = 0;
1287 1332 while (p != NULL) { while (p != NULL) {
1288 1333 s += p->size; s += p->size;
1289 1334 p = p->prev; p = p->prev;
1290 1335 }; };
1291 s += (cv->mfocus->size / 2);
1292 p = cv->mfocus->track->next->c;
1336 s += (cs->v->mfocus->size / 2);
1337 p = cs->v->mfocus->track->next->c;
1293 1338 while (p->next != NULL) { while (p->next != NULL) {
1294 1339 t += p->size; t += p->size;
1295 1340 if (t >= s) {break;}; if (t >= s) {break;};
1296 1341 p = p->next; p = p->next;
1297 1342 }; };
1298 cv->mfocus = p;
1343 cs->v->mfocus = p;
1299 1344 }; };
1300 } else if (dir == 4 && cv->mfocus->track->prev != NULL) {
1301 if (cv->fs == false) {
1345 } else if (dir == 4 && cs->v->mfocus->track->prev != NULL) {
1346 if (cs->v->fs == false) {
1302 1347 struct cont *p; struct cont *p;
1303 p = cv->mfocus->prev;
1348 p = cs->v->mfocus->prev;
1304 1349 int s = 0; int s = 0;
1305 1350 int t = 0; int t = 0;
1306 1351 while (p != NULL) { while (p != NULL) {
1307 1352 s += p->size; s += p->size;
1308 1353 p = p->prev; p = p->prev;
1309 1354 }; };
1310 s += (cv->mfocus->size / 2);
1311 p = cv->mfocus->track->prev->c;
1355 s += (cs->v->mfocus->size / 2);
1356 p = cs->v->mfocus->track->prev->c;
1312 1357 while (p->next != NULL) { while (p->next != NULL) {
1313 1358 t += p->size; t += p->size;
1314 1359 if (t >= s) {break;}; if (t >= s) {break;};
1315 1360 p = p->next; p = p->next;
1316 1361 }; };
1317 cv->mfocus = p;
1362 cs->v->mfocus = p;
1318 1363 }; };
1319 1364 }; };
1320 1365 } }
 
... ... struct view * find_view (int i) {
1328 1373 struct view *v = NULL; struct view *v = NULL;
1329 1374 if (i == -2) { if (i == -2) {
1330 1375 //move forward //move forward
1331 if (cv->next != NULL) {
1332 return(cv->next);
1376 if (cs->v->next != NULL) {
1377 return(cs->v->next);
1333 1378 } else { } else {
1334 //make cv->next
1379 //make cs->v->next
1335 1380 v = make_view(); v = make_view();
1336 cv->next = v;
1337 v->prev = cv;
1338 v->idx = (cv->idx + 1);
1381 cs->v->next = v;
1382 v->prev = cs->v;
1383 v->idx = (cs->v->idx + 1);
1339 1384 }; };
1340 1385 } else if (i == -3) { } else if (i == -3) {
1341 1386 //move backward //move backward
1342 if (cv->prev != NULL) {
1343 return(cv->prev);
1387 if (cs->v->prev != NULL) {
1388 return(cs->v->prev);
1344 1389 } else { } else {
1345 //make cv->prev
1390 //make cs->v->prev
1346 1391 v = make_view(); v = make_view();
1347 v->next = cv;
1348 cv->prev = v;
1349 v->idx = (cv->idx - 1);
1392 v->next = cs->v;
1393 cs->v->prev = v;
1394 v->idx = (cs->v->idx - 1);
1350 1395 fv = v; fv = v;
1351 1396 }; };
1352 1397 } else if (i == -1) { } else if (i == -1) {
1353 v = cv;
1398 v = cs->v;
1354 1399 while (v->next != NULL) { while (v->next != NULL) {
1355 1400 v = v->next; v = v->next;
1356 1401 }; };
 
... ... struct view * find_view (int i) {
1396 1441
1397 1442 void goto_view(struct view *v) { void goto_view(struct view *v) {
1398 1443 //this just unmaps the windows of the current view //this just unmaps the windows of the current view
1399 //sets cv
1400 //and maps the windows of the new cv
1444 //sets cs->v
1445 //and maps the windows of the new cs->v
1401 1446 //it also deletes empty views //it also deletes empty views
1402 if (v == NULL || v == cv) {return;};
1403 struct track *t = cv->ft;
1447 if (v == NULL || v == cs->v) {return;};
1448 struct track *t = cs->v->ft;
1404 1449 struct cont *c; struct cont *c;
1405 1450 while (t != NULL) { while (t != NULL) {
1406 1451 c = t->c; c = t->c;
 
... ... void goto_view(struct view *v) {
1410 1455 }; };
1411 1456 t = t->next; t = t->next;
1412 1457 }; };
1413 if (cv->mfocus == NULL && cv->sfocus == NULL) {
1414 if (cv->prev != NULL) {
1415 cv->prev->next = cv->next;
1458 if (cs->v->mfocus == NULL && cs->v->sfocus == NULL) {
1459 if (cs->v->prev != NULL) {
1460 cs->v->prev->next = cs->v->next;
1416 1461 }; };
1417 if (cv->next != NULL) {
1418 cv->next->prev = cv->prev;
1462 if (cs->v->next != NULL) {
1463 cs->v->next->prev = cs->v->prev;
1419 1464 }; };
1420 if (cv == fv) {
1421 fv = cv->next;
1465 if (cs->v == fv) {
1466 fv = cs->v->next;
1422 1467 }; };
1423 free(cv);
1468 free(cs->v);
1424 1469 }; };
1425 cv = v;
1470 cs->v = v;
1426 1471 t = v->ft; t = v->ft;
1427 1472 while (t != NULL) { while (t != NULL) {
1428 1473 c = t->c; c = t->c;
 
... ... void goto_view(struct view *v) {
1437 1482
1438 1483 void move_to_view(struct view *v) { void move_to_view(struct view *v) {
1439 1484 //move currenlty focused item //move currenlty focused item
1440 if (v == NULL || v == cv || cv->mfocus == NULL) {return;};
1485 if (v == NULL || v == cs->v || cs->v->mfocus == NULL) {return;};
1441 1486 //remove it from the current view //remove it from the current view
1442 struct win *w = cv->mfocus->win;
1487 struct win *w = cs->v->mfocus->win;
1443 1488 XUnmapWindow(dpy,w->id); XUnmapWindow(dpy,w->id);
1444 remove_cont(cv->mfocus);
1489 remove_cont(cs->v->mfocus);
1445 1490 //add it to the new view //add it to the new view
1446 1491 add_client_to_view(w, v); add_client_to_view(w, v);
1447 1492 } }
1448 1493
1449 1494 struct cont * id_to_cont(Window w) { struct cont * id_to_cont(Window w) {
1450 struct track *t = cv->ft;
1495 struct track *t = cs->v->ft;
1451 1496 struct cont *c; struct cont *c;
1452 1497 while (t != NULL) { while (t != NULL) {
1453 1498 c = t->c; c = t->c;
 
... ... struct cont * id_to_cont(Window w) {
1463 1508 } }
1464 1509
1465 1510 void resize (int dir) { void resize (int dir) {
1466 if (cv->orientv == true) {
1511 if (cs->v->orientv == true) {
1467 1512 switch (dir) { switch (dir) {
1468 1513 case 1: case 1:
1469 cv->mfocus->size -= resize_inc;
1514 cs->v->mfocus->size -= resize_inc;
1470 1515 break; break;
1471 1516 case 2: case 2:
1472 cv->mfocus->track->size += resize_inc;
1517 cs->v->mfocus->track->size += resize_inc;
1473 1518 break; break;
1474 1519 case 3: case 3:
1475 cv->mfocus->size += resize_inc;
1520 cs->v->mfocus->size += resize_inc;
1476 1521 break; break;
1477 1522 case 4: case 4:
1478 cv->mfocus->track->size -= resize_inc;
1523 cs->v->mfocus->track->size -= resize_inc;
1479 1524 break; break;
1480 1525 }; };
1481 1526 } else { } else {
1482 1527 switch (dir) { switch (dir) {
1483 1528 case 1: case 1:
1484 cv->mfocus->track->size += resize_inc;
1529 cs->v->mfocus->track->size += resize_inc;
1485 1530 break; break;
1486 1531 case 2: case 2:
1487 cv->mfocus->size += resize_inc;
1532 cs->v->mfocus->size += resize_inc;
1488 1533 break; break;
1489 1534 case 3: case 3:
1490 cv->mfocus->track->size -= resize_inc;
1535 cs->v->mfocus->track->size -= resize_inc;
1491 1536 break; break;
1492 1537 case 4: case 4:
1493 cv->mfocus->size -= resize_inc;
1538 cs->v->mfocus->size -= resize_inc;
1494 1539 break; break;
1495 1540 }; };
1496 1541 }; };
1497 1542 } }
1498 1543
1499 1544 void layout() { void layout() {
1500 int stackheight;
1501 if (cv->showstack == false || cv->fs == true) {
1502 stackheight = 0;
1503 } else {
1504 struct stack_item *si = cv->stack;
1505 int i = 0;
1506 while (si != NULL) {
1507 i++;
1508 si = si->next;
1509 };
1510 stackheight = (i * 20);
1511 if (i == 0) {
1512 stackheight = 8;
1513 };
1514 };
1515 //draw the stack
1516 XClearWindow(dpy,stackid);
1517 if (stackheight != 0) {
1518 XMoveResizeWindow(dpy,stackid,(res_left),((scrn_h - res_bot) - (stackheight)),(scrn_w - (res_left + res_right)),(stackheight));
1519 XRaiseWindow(dpy,stackid);
1520 XSync(dpy,false);//important!
1521 struct stack_item *si = cv->stack;
1522 int i = 15;
1523 while (si != NULL) {
1524 GC gc;
1525 if (si == cv->sfocus) {
1526 gc = focus_gc;
1527 } else {
1528 gc = unfocus_gc;
1529 };
1530 XTextProperty wmname;
1531 XGetWMName(dpy,si->win->id,&wmname);
1532 XDrawString(dpy,stackid,gc,3,i, (char *) wmname.value,wmname.nitems);
1533 si = si->next;
1534 i += 20;
1535 };
1536 } else { //hide stack
1537 XMoveResizeWindow(dpy,stackid,0,(scrn_h ),scrn_w,10);
1538 };
1539 XSync(dpy,false);
1540 if (cv->mfocus == NULL) {
1541 XSetInputFocus(dpy,root,None,CurrentTime);
1542 };
1543 if (cv->fs == true && cv->mfocus != NULL && cv->mfocus->win != NULL) {
1544 //draw mf fullscreen
1545 int w = scrn_w + 2;
1546 int h = scrn_h;
1547 /* if (cv->showstack == true) {
1548 h += 1;
1545 struct screen *s = firstscreen;
1546 while (s != NULL) {
1547 int xo = s->x;
1548 int yo = s->y;
1549 int stackheight;
1550 if (s->v->showstack == false || s->v->fs == true) {
1551 stackheight = 0;
1549 1552 } else { } else {
1550 h += 2;
1553 struct stack_item *si = s->v->stack;
1554 int i = 0;
1555 while (si != NULL) {
1556 i++;
1557 si = si->next;
1558 };
1559 stackheight = (i * 20);
1560 if (i == 0) {
1561 stackheight = 8;
1562 };
1551 1563 }; };
1552 These lines shouldn't be necessary AS LONG AS we are hidding the stack in fs
1553 */
1554 h -= stackheight;
1555 XMoveResizeWindow(dpy,cv->mfocus->win->id,(-1),(-1),(w),(h));
1556 XRaiseWindow(dpy,cv->mfocus->win->id);
1557 if (cv->mfocus->win->take_focus == true) {
1558 XClientMessageEvent cm;
1559 memset (&cm,'\0', sizeof(cm));
1560 cm.type = ClientMessage;
1561 cm.window = cv->mfocus->win->id;
1562 cm.message_type = wm_prot;
1563 cm.format = 32;
1564 cm.data.l[0] = wm_take_focus;
1565 cm.data.l[1] = CurrentTime;
1564 //draw the stack
1565 XClearWindow(dpy,s->stackid);
1566 if (stackheight != 0) {
1567 XMoveResizeWindow(dpy,s->stackid,(res_left + yo),((s->h - res_bot) - (stackheight)),(s->w - (res_left + yo + res_right)),(stackheight));
1568 XRaiseWindow(dpy,s->stackid);
1569 XSync(dpy,false);//important!
1570 struct stack_item *si = s->v->stack;
1571 int i = 15;
1572 while (si != NULL) {
1573 GC gc;
1574 if (si == s->v->sfocus) {
1575 gc = focus_gc;
1576 } else {
1577 gc = unfocus_gc;
1578 };
1579 XTextProperty wmname;
1580 XGetWMName(dpy,si->win->id,&wmname);
1581 XDrawString(dpy,s->stackid,gc,3,i, (char *) wmname.value,wmname.nitems);
1582 si = si->next;
1583 i += 20;
1584 };
1585 } else { //hide stack
1586 XMoveResizeWindow(dpy,s->stackid,0,(s->h ),s->w,10);
1566 1587 }; };
1567 XSetInputFocus(dpy,cv->mfocus->win->id,None,CurrentTime);
1568 1588 XSync(dpy,false); XSync(dpy,false);
1569 } else {
1570 //first check that the tracks layout:
1571 struct track *curt = cv->ft;
1572 struct cont *curc = NULL;
1573 int target;
1574 int tot = 0;
1575 if (cv->orientv == true) {
1576 target = scrn_w - (res_left + res_right);
1577 } else {
1578 if (cv->showstack == true) {
1579 target = (scrn_h - (res_top + res_bot)) - stackheight;
1580 } else {
1581 target = scrn_h - (res_top + res_bot);
1582 };
1589 if (s->v->mfocus == NULL) {
1590 XSetInputFocus(dpy,root,None,CurrentTime);
1583 1591 }; };
1584 int nooftracks = 0;
1585 while (curt != NULL) {
1586 //check if the size is negligably small, requireing a reseize
1587 if (curt->size <= 5) {
1588 curt->size += 40;
1592 if (s->v->fs == true && s->v->mfocus != NULL && s->v->mfocus->win != NULL) {
1593 //draw mf fullscreen
1594 int w = s->w + 2;
1595 int h = s->h;
1596 /* if (s->v->showstack == true) {
1597 h += 1;
1598 } else {
1599 h += 2;
1589 1600 }; };
1590 tot += curt->size;
1591 curt = curt->next;
1592 nooftracks ++;
1593 };
1594 //compare tot to target, if they match go on
1595 if (tot != target) {
1596 signed int delta = target - tot;
1597 delta /= nooftracks;
1598 curt = cv->ft;
1599 while (curt != NULL) {
1600 curt->size += delta;
1601 curt = curt->next;
1601 These lines shouldn't be necessary AS LONG AS we are hidding the stack in fs
1602 */
1603 h -= stackheight;
1604 XMoveResizeWindow(dpy,s->v->mfocus->win->id,(-1),(-1),(w),(h));
1605 XRaiseWindow(dpy,s->v->mfocus->win->id);
1606 if (s->v->mfocus->win->take_focus == true) {
1607 XClientMessageEvent cm;
1608 memset (&cm,'\0', sizeof(cm));
1609 cm.type = ClientMessage;
1610 cm.window = s->v->mfocus->win->id;
1611 cm.message_type = wm_prot;
1612 cm.format = 32;
1613 cm.data.l[0] = wm_take_focus;
1614 cm.data.l[1] = CurrentTime;
1602 1615 }; };
1603 };
1604 //else calculate the difference, and adjust all tracks
1605 //second check that within each track the containers fit
1606 curt = cv->ft;
1607 if (cv->orientv != true) {
1608 target = scrn_w - (res_left + res_right);
1616 XSetInputFocus(dpy,s->v->mfocus->win->id,None,CurrentTime);
1617 XSync(dpy,false);
1609 1618 } else { } else {
1610 if (cv->showstack == true) {
1611 target = (scrn_h - (res_top + res_bot)) - stackheight;
1619 //first check that the tracks layout:
1620 struct track *curt = s->v->ft;
1621 struct cont *curc = NULL;
1622 int target;
1623 int tot = 0;
1624 if (s->v->orientv == true) {
1625 target = s->w - (res_left + res_right);
1612 1626 } else { } else {
1613 target = (scrn_h - (res_top + res_bot));
1627 if (s->v->showstack == true) {
1628 target = (s->h - (res_top + res_bot)) - stackheight;
1629 } else {
1630 target = s->h - (res_top + res_bot);
1631 };
1614 1632 }; };
1615 };
1616 while (curt != NULL) {
1617 curc = curt->c;
1618 int tot = 0;
1619 int noofconts = 0;
1620 while (curc != NULL) {
1621 //check for cont with negligable size and resize if necessary
1622 if (curc->size <= 5) {
1623 curc->size += 40;
1633 int nooftracks = 0;
1634 while (curt != NULL) {
1635 //check if the size is negligably small, requireing a reseize
1636 if (curt->size <= 5) {
1637 curt->size += 40;
1624 1638 }; };
1625 noofconts ++;
1626 tot += curc->size;
1627 curc = curc->next;
1639 tot += curt->size;
1640 curt = curt->next;
1641 nooftracks ++;
1628 1642 }; };
1629 //if tot == target, do nothing
1630 //else calculate and distribute difference
1643 //compare tot to target, if they match go on
1631 1644 if (tot != target) { if (tot != target) {
1632 1645 signed int delta = target - tot; signed int delta = target - tot;
1633 if (noofconts != 0) {
1634 delta /= noofconts;
1646 delta /= nooftracks;
1647 curt = s->v->ft;
1648 while (curt != NULL) {
1649 curt->size += delta;
1650 curt = curt->next;
1651 };
1652 };
1653 //else calculate the difference, and adjust all tracks
1654 //second check that within each track the containers fit
1655 curt = s->v->ft;
1656 if (s->v->orientv != true) {
1657 target = s->w - (res_left + res_right);
1658 } else {
1659 if (s->v->showstack == true) {
1660 target = (s->h - (res_top + res_bot)) - stackheight;
1635 1661 } else { } else {
1636 delta = 0;
1662 target = (s->h - (res_top + res_bot));
1637 1663 }; };
1664 };
1665 while (curt != NULL) {
1638 1666 curc = curt->c; curc = curt->c;
1667 int tot = 0;
1668 int noofconts = 0;
1639 1669 while (curc != NULL) { while (curc != NULL) {
1640 curc->size += delta;
1670 //check for cont with negligable size and resize if necessary
1671 if (curc->size <= 5) {
1672 curc->size += 40;
1673 };
1674 noofconts ++;
1675 tot += curc->size;
1641 1676 curc = curc->next; curc = curc->next;
1642 1677 }; };
1643 };
1644 curt = curt->next;
1645 };
1646 //walk and draw
1647 curt = cv->ft; //first track of view
1648 int x;
1649 int y;
1650 int h;
1651 int w;
1652 int offsett = 0;
1653 int offsetc = 0;
1654 while (curt != NULL) {
1655 offsetc = 0;
1656 curc = curt->c;
1657 while (curc != NULL) {
1658 //make sure we tell windows that think they are fs that they aren't
1659 if (curc->win->fullscreen == true) {
1660 curc->win->fullscreen = false;
1661 XChangeProperty(dpy,curc->win->id,wm_change_state,XA_ATOM,32,PropModeReplace,(unsigned char *)0,0);
1662 };
1663 if (curc == cv->mfocus) {
1664 //set border
1665 XSetWindowBorder(dpy,curc->win->id,focus_pix);
1666 if (cv->mfocus->win->take_focus == true) {
1667 XClientMessageEvent cm;
1668 memset (&cm,'\0', sizeof(cm));
1669 cm.type = ClientMessage;
1670 cm.window = cv->mfocus->win->id;
1671 cm.message_type = wm_prot;
1672 cm.format = 32;
1673 cm.data.l[0] = wm_take_focus;
1674 cm.data.l[1] = CurrentTime;
1675 };
1676 //we intentionally do this even if the event was sent, the
1677 //event alone does not suffice to get focus on the window
1678 XSetInputFocus(dpy,curc->win->id,None,CurrentTime);
1679
1680
1681 } else {
1682 XSetWindowBorder(dpy,curc->win->id,unfocus_pix);
1678 //if tot == target, do nothing
1679 //else calculate and distribute difference
1680 if (tot != target) {
1681 signed int delta = target - tot;
1682 if (noofconts != 0) {
1683 delta /= noofconts;
1684 } else {
1685 delta = 0;
1686 };
1687 curc = curt->c;
1688 while (curc != NULL) {
1689 curc->size += delta;
1690 curc = curc->next;
1691 };
1683 1692 }; };
1684 //place window
1685 if (cv->orientv == true) {
1686 x = offsett + res_left;
1687 y = offsetc + res_top;
1688 w = curt->size - 2;
1689 h = curc->size - 2;
1690 } else {
1691 x = offsetc + res_left;
1692 y = offsett + res_top;
1693 w = curc->size - 2;
1694 h = curt->size - 2;
1693 curt = curt->next;
1694 };
1695 //walk and draw
1696 curt = s->v->ft; //first track of view
1697 int x;
1698 int y;
1699 int h;
1700 int w;
1701 int offsett = 0;
1702 int offsetc = 0;
1703 while (curt != NULL) {
1704 offsetc = 0;
1705 curc = curt->c;
1706 while (curc != NULL) {
1707 //make sure we tell windows that think they are fs that they aren't
1708 if (curc->win->fullscreen == true) {
1709 curc->win->fullscreen = false;
1710 XChangeProperty(dpy,curc->win->id,wm_change_state,XA_ATOM,32,PropModeReplace,(unsigned char *)0,0);
1711 };
1712 if (curc == s->v->mfocus) {
1713 //set border
1714 XSetWindowBorder(dpy,curc->win->id,focus_pix);
1715 if (s->v->mfocus->win->take_focus == true) {
1716 XClientMessageEvent cm;
1717 memset (&cm,'\0', sizeof(cm));
1718 cm.type = ClientMessage;
1719 cm.window = s->v->mfocus->win->id;
1720 cm.message_type = wm_prot;
1721 cm.format = 32;
1722 cm.data.l[0] = wm_take_focus;
1723 cm.data.l[1] = CurrentTime;
1724 };
1725 //we intentionally do this even if the event was sent, the
1726 //event alone does not suffice to get focus on the window
1727 XSetInputFocus(dpy,curc->win->id,None,CurrentTime);
1728
1729
1730 } else {
1731 XSetWindowBorder(dpy,curc->win->id,unfocus_pix);
1732 };
1733 //place window
1734 if (s->v->orientv == true) {
1735 x = offsett + res_left + yo;
1736 y = offsetc + res_top + xo;
1737 w = curt->size - 2;
1738 h = curc->size - 2;
1739 } else {
1740 x = offsetc + res_left + yo;
1741 y = offsett + res_top + xo;
1742 w = curc->size - 2;
1743 h = curt->size - 2;
1744 };
1745 XMoveResizeWindow(dpy,curc->win->id,(x),(y),(w),(h));
1746 offsetc += curc->size;
1747 curc = curc->next;
1695 1748 }; };
1696 XMoveResizeWindow(dpy,curc->win->id,(x),(y),(w),(h));
1697 offsetc += curc->size;
1698 curc = curc->next;
1749 offsett += curt->size;
1750 curt = curt->next;
1699 1751 }; };
1700 offsett += curt->size;
1701 curt = curt->next;
1702 1752 }; };
1753 s = s->next;
1703 1754 }; };
1704 1755 } }
1705 1756
 
... ... int event_loop() {
1726 1777 redraw = false; //this will get set to true if something gets changed onscreen redraw = false; //this will get set to true if something gets changed onscreen
1727 1778 do { do {
1728 1779 XNextEvent(dpy, &ev); XNextEvent(dpy, &ev);
1729 if (ev.type == MotionNotify && sloppy_focus == true && cv->fs == false) {
1730 if (cv->mfocus->win->id != ev.xmotion.window) {
1780 if (ev.type == MotionNotify && sloppy_focus == true && cs->v->fs == false) {
1781 if (cs->v->mfocus->win->id != ev.xmotion.window) {
1731 1782 struct cont *f = id_to_cont(ev.xmotion.window); struct cont *f = id_to_cont(ev.xmotion.window);
1732 1783 if (f != NULL) { if (f != NULL) {
1733 cv->mfocus = f;
1784 cs->v->mfocus = f;
1734 1785 redraw = true; redraw = true;
1735 1786 }; };
1736 1787 }; };
1737 } else if (ev.type == EnterNotify && cv->fs == false && ev.xcrossing.focus == false && sloppy_focus == true) {
1788 } else if (ev.type == EnterNotify && cs->v->fs == false && ev.xcrossing.focus == false && sloppy_focus == true) {
1738 1789 struct timeval ctime; struct timeval ctime;
1739 1790 gettimeofday(&ctime,0); gettimeofday(&ctime,0);
1740 1791 signed long usec = ctime.tv_usec - last_redraw.tv_usec; signed long usec = ctime.tv_usec - last_redraw.tv_usec;
1741 1792 signed long sec = ctime.tv_sec - last_redraw.tv_sec; signed long sec = ctime.tv_sec - last_redraw.tv_sec;
1742 1793 if ( sec > 1 || (sec == 0 && usec >= 20000) || (sec == 1 && usec <= -20000)) { if ( sec > 1 || (sec == 0 && usec >= 20000) || (sec == 1 && usec <= -20000)) {
1743 if (cv->mfocus->win->id != ev.xcrossing.window) {
1794 if (cs->v->mfocus->win->id != ev.xcrossing.window) {
1744 1795 struct cont *f = id_to_cont(ev.xmotion.window); struct cont *f = id_to_cont(ev.xmotion.window);
1745 1796 if (f != NULL) { if (f != NULL) {
1746 cv->mfocus = f;
1797 cs->v->mfocus = f;
1747 1798 redraw = true; redraw = true;
1748 1799 }; };
1749 1800 }; };
 
... ... int event_loop() {
1894 1945 break; break;
1895 1946 //toggle stack //toggle stack
1896 1947 case 32: case 32:
1897 if (cv->fs == false) {
1898 if (cv->showstack == true) {
1899 cv->showstack = false;
1948 if (cs->v->fs == false) {
1949 if (cs->v->showstack == true) {
1950 cs->v->showstack = false;
1900 1951 } else { } else {
1901 cv->showstack = true;
1952 cs->v->showstack = true;
1902 1953 }; };
1903 1954 redraw = true; redraw = true;
1904 1955 }; };
1905 1956 break; break;
1906 1957 //move to stack //move to stack
1907 1958 case 33: case 33:
1908 if (cv->mfocus == NULL) {break;};
1909 if (cv->fs == true) {break;};
1910 XUnmapWindow(dpy,cv->mfocus->win->id);
1911 move_to_stack(cv->mfocus);
1959 if (cs->v->mfocus == NULL) {break;};
1960 if (cs->v->fs == true) {break;};
1961 XUnmapWindow(dpy,cs->v->mfocus->win->id);
1962 move_to_stack(cs->v->mfocus);
1912 1963 redraw = true; redraw = true;
1913 1964 break; break;
1914 1965 //move to main //move to main
1915 1966 case 34: case 34:
1916 if (cv->fs == true) {break;};
1967 if (cs->v->fs == true) {break;};
1917 1968 move_to_main(); move_to_main();
1918 if (cv->mfocus != NULL && cv->mfocus->win != NULL) {
1919 XMapWindow(dpy,cv->mfocus->win->id);
1969 if (cs->v->mfocus != NULL && cs->v->mfocus->win != NULL) {
1970 XMapWindow(dpy,cs->v->mfocus->win->id);
1920 1971 }; };
1921 1972 redraw = true; redraw = true;
1922 1973 break; break;
1923 1974 //flip the layout //flip the layout
1924 1975 case 35: case 35:
1925 if (cv->fs == true) {break;};
1926 if (cv->sfocus != NULL && cv->mfocus != NULL) {
1927 struct win *m = cv->mfocus->win;
1928 struct win *s = cv->sfocus->win;
1929 cv->mfocus->win = s;
1930 cv->sfocus->win = m;
1931 XMapWindow(dpy,cv->mfocus->win->id);
1932 XUnmapWindow(dpy,cv->sfocus->win->id);
1976 if (cs->v->fs == true) {break;};
1977 if (cs->v->sfocus != NULL && cs->v->mfocus != NULL) {
1978 struct win *m = cs->v->mfocus->win;
1979 struct win *s = cs->v->sfocus->win;
1980 cs->v->mfocus->win = s;
1981 cs->v->sfocus->win = m;
1982 XMapWindow(dpy,cs->v->mfocus->win->id);
1983 XUnmapWindow(dpy,cs->v->sfocus->win->id);
1933 1984 XSync(dpy,False); XSync(dpy,False);
1934 1985 redraw = true; redraw = true;
1935 1986 }; };
1936 1987 break; break;
1937 1988 //swap stack up/down //swap stack up/down
1938 1989 case 36: case 36:
1939 if (cv->sfocus != NULL && cv->sfocus->prev != NULL) {
1990 if (cs->v->sfocus != NULL && cs->v->sfocus->prev != NULL) {
1940 1991 struct stack_item *tmpa, *tmpb, *tmpc, *tmpd; struct stack_item *tmpa, *tmpb, *tmpc, *tmpd;
1941 tmpa = cv->sfocus->prev->prev;
1942 tmpb = cv->sfocus->prev;
1943 tmpc = cv->sfocus;
1944 tmpd =cv->sfocus->next;
1992 tmpa = cs->v->sfocus->prev->prev;
1993 tmpb = cs->v->sfocus->prev;
1994 tmpc = cs->v->sfocus;
1995 tmpd =cs->v->sfocus->next;
1945 1996 if (tmpa != NULL) { if (tmpa != NULL) {
1946 1997 tmpa->next = tmpc; tmpa->next = tmpc;
1947 1998 } else { } else {
1948 cv->stack = tmpc;
1999 cs->v->stack = tmpc;
1949 2000 }; };
1950 2001 if (tmpd != NULL) { if (tmpd != NULL) {
1951 2002 tmpd->prev = tmpb; tmpd->prev = tmpb;
 
... ... int event_loop() {
1958 2009 redraw = true; redraw = true;
1959 2010 break; break;
1960 2011 case 37: case 37:
1961 if (cv->sfocus != NULL && cv->sfocus->next != NULL) {
2012 if (cs->v->sfocus != NULL && cs->v->sfocus->next != NULL) {
1962 2013 struct stack_item *tmpa, *tmpb, *tmpc, *tmpd; struct stack_item *tmpa, *tmpb, *tmpc, *tmpd;
1963 tmpa = cv->sfocus->prev;
1964 tmpb = cv->sfocus;
1965 tmpc = cv->sfocus->next;
1966 tmpd =cv->sfocus->next->next;
2014 tmpa = cs->v->sfocus->prev;
2015 tmpb = cs->v->sfocus;
2016 tmpc = cs->v->sfocus->next;
2017 tmpd =cs->v->sfocus->next->next;
1967 2018 if (tmpa != NULL) { if (tmpa != NULL) {
1968 2019 tmpa->next = tmpc; tmpa->next = tmpc;
1969 2020 } else { } else {
1970 cv->stack = tmpc;
2021 cs->v->stack = tmpc;
1971 2022 }; };
1972 2023 if (tmpd != NULL) { if (tmpd != NULL) {
1973 2024 tmpd->prev = tmpb; tmpd->prev = tmpb;
 
... ... int event_loop() {
2007 2058 break; break;
2008 2059 //close win soft or hard //close win soft or hard
2009 2060 case 44: case 44:
2010 if (cv->mfocus == NULL || cv->mfocus->win == NULL) {
2061 if (cs->v->mfocus == NULL || cs->v->mfocus->win == NULL) {
2011 2062 break; break;
2012 2063 }; };
2013 if (cv->mfocus->win->del_win == true) {
2064 if (cs->v->mfocus->win->del_win == true) {
2014 2065 XClientMessageEvent cm; XClientMessageEvent cm;
2015 2066 memset(&cm,'\0', sizeof cm); memset(&cm,'\0', sizeof cm);
2016 2067 cm.type = ClientMessage; cm.type = ClientMessage;
2017 cm.window = cv->mfocus->win->id;
2068 cm.window = cs->v->mfocus->win->id;
2018 2069 cm.message_type = wm_prot; cm.message_type = wm_prot;
2019 2070 cm.format = 32; cm.format = 32;
2020 2071 cm.data.l[0] = wm_del_win; cm.data.l[0] = wm_del_win;
2021 2072 cm.data.l[1] = CurrentTime; cm.data.l[1] = CurrentTime;
2022 XSendEvent(dpy, cv->mfocus->win->id, False, 0L, (XEvent *)&cm);
2073 XSendEvent(dpy, cs->v->mfocus->win->id, False, 0L, (XEvent *)&cm);
2023 2074 } else { } else {
2024 XDestroyWindow(dpy,cv->mfocus->win->id);
2075 XDestroyWindow(dpy,cs->v->mfocus->win->id);
2025 2076 }; };
2026 2077 break; break;
2027 2078 case 45: case 45:
2028 if (cv->mfocus != NULL && cv->mfocus->win != NULL) {
2029 XKillClient(dpy,cv->mfocus->win->id);
2079 if (cs->v->mfocus != NULL && cs->v->mfocus->win != NULL) {
2080 XKillClient(dpy,cs->v->mfocus->win->id);
2030 2081 }; };
2031 2082 break; break;
2032 2083 //run menu/xterm //run menu/xterm
 
... ... int event_loop() {
2039 2090 break; break;
2040 2091 //fullscreen: //fullscreen:
2041 2092 case 48: case 48:
2042 if (cv->fs == true) {
2043 cv->fs = false;
2093 if (cs->v->fs == true) {
2094 cs->v->fs = false;
2044 2095 } else { } else {
2045 cv->fs = true;
2096 cs->v->fs = true;
2046 2097 }; };
2047 2098 redraw = true; redraw = true;
2048 2099 break; break;
 
... ... int event_loop() {
2051 2102 return(0); return(0);
2052 2103 break; break;
2053 2104 case 50: case 50:
2054 if (cv->orientv == true) {
2055 cv->orientv = false;
2105 if (cs->v->orientv == true) {
2106 cs->v->orientv = false;
2056 2107 } else { } else {
2057 cv->orientv = true;
2108 cs->v->orientv = true;
2058 2109 }; };
2059 2110 redraw = true; redraw = true;
2060 2111 break; break;
 
... ... int event_loop() {
2149 2200 XFreeGC(dpy,unfocus_gc); XFreeGC(dpy,unfocus_gc);
2150 2201 XGCValues xgcv; XGCValues xgcv;
2151 2202 xgcv.foreground = stack_focus_pix; xgcv.foreground = stack_focus_pix;
2152 focus_gc = XCreateGC(dpy,stackid,GCForeground,&xgcv);
2203 focus_gc = XCreateGC(dpy,cs->stackid,GCForeground,&xgcv);
2153 2204 xgcv.foreground = stack_unfocus_pix; xgcv.foreground = stack_unfocus_pix;
2154 unfocus_gc = XCreateGC(dpy,stackid,GCForeground,&xgcv);
2205 unfocus_gc = XCreateGC(dpy,cs->stackid,GCForeground,&xgcv);
2155 2206 }; };
2156 2207 }; };
2157 2208
 
... ... int event_loop() {
2163 2214 XWindowAttributes att; XWindowAttributes att;
2164 2215 XGetWindowAttributes (dpy,ev.xreparent.window,&att); XGetWindowAttributes (dpy,ev.xreparent.window,&att);
2165 2216 if (att.map_state != IsUnmapped) { if (att.map_state != IsUnmapped) {
2166 add_client_to_view(t,cv);
2217 add_client_to_view(t,cs->v);
2167 2218 redraw = true; redraw = true;
2168 2219 }; };
2169 2220 }; };
 
... ... int event_loop() {
2205 2256 w = add_win(ev.xmap.window); w = add_win(ev.xmap.window);
2206 2257 }; };
2207 2258 //finally add to layout //finally add to layout
2208 add_client_to_view(w,cv);
2259 add_client_to_view(w,cs->v);
2209 2260 redraw = true; redraw = true;
2210 2261 }; };
2211 2262 } else if (ev.type == UnmapNotify ) { } else if (ev.type == UnmapNotify ) {
 
... ... int event_loop() {
2213 2264 s = id_to_cont(ev.xunmap.window); s = id_to_cont(ev.xunmap.window);
2214 2265 if (s != NULL ) { if (s != NULL ) {
2215 2266
2216 if (s->track->view == cv) {
2217 cv->fs = false;
2267 if (s->track->view == cs->v) {
2268 cs->v->fs = false;
2218 2269 }; };
2219 2270 remove_cont(s); remove_cont(s);
2220 2271 //unless we caused this, we should check the window's original state //unless we caused this, we should check the window's original state
 
... ... int event_loop() {
2227 2278 //if a window tries to manage itself we are going to play rough //if a window tries to manage itself we are going to play rough
2228 2279 struct cont *wc = id_to_cont(ev.xconfigure.window); struct cont *wc = id_to_cont(ev.xconfigure.window);
2229 2280 if (wc != NULL) { if (wc != NULL) {
2230 if (wc->track->view == cv) {
2281 if (wc->track->view == cs->v) {
2231 2282 if (wc->track->view->orientv == true) { if (wc->track->view->orientv == true) {
2232 2283 //we are going to be niave and just check the w and h //we are going to be niave and just check the w and h
2233 2284 //w =track size //w =track size
 
... ... int main() {
2257 2308
2258 2309 dpy = XOpenDisplay(0); dpy = XOpenDisplay(0);
2259 2310 XSetErrorHandler(xerror); XSetErrorHandler(xerror);
2260 scrn_h = DisplayHeight(dpy,DefaultScreen(dpy));
2261 scrn_w = DisplayWidth(dpy,DefaultScreen(dpy));
2262 printf("euclid-wm: sreen dimensions: %d %d\n",scrn_h, scrn_w);
2311 // cs->h = DisplayHeight(dpy,DefaultScreen(dpy));
2312 // cs->w = DisplayWidth(dpy,DefaultScreen(dpy));
2313 // printf("euclid-wm: sreen dimensions: %d %d\n",cs->h, cs->w);
2263 2314 //set some stuff //set some stuff
2264 2315 if ((root = DefaultRootWindow(dpy))) { if ((root = DefaultRootWindow(dpy))) {
2265 2316 printf("euclid-wm: root is %6.0lx\n",root); printf("euclid-wm: root is %6.0lx\n",root);
 
... ... int main() {
2313 2364
2314 2365
2315 2366 set_atoms(); set_atoms();
2316 int i;
2317 cv = make_view();
2318 fv = cv;
2319 cv->idx = 1;
2367 int screens;
2368 XineramaScreenInfo *scrn_info = NULL;
2369 scrn_info = XineramaQueryScreens(dpy,&screens);
2370 printf("screens %d\n",screens);
2371 unsigned short sn = 0;
2372 if (screens == 0) {
2373 printf("Xinerama diabled\n");
2374 addscreen( DisplayHeight(dpy,DefaultScreen(dpy)),DisplayWidth(dpy,DefaultScreen(dpy)),0,0,0);
2375
2376 } else {
2377 printf("Xinerama enabled: %d screens\n",screens);
2378 while (sn < screens) {
2379 addscreen(scrn_info[sn].height,scrn_info[sn].width,scrn_info[sn].x_org,scrn_info[sn].y_org,sn);
2380 sn ++;
2381 };
2382 };
2383 XFree(scrn_info);
2384
2385 // cs->v = make_view();
2386 // fv = cs->v;
2387 // cs->v->idx = 1;
2320 2388
2321 2389 //now we also need to get all already exisiting windows //now we also need to get all already exisiting windows
2322 2390 Window d1, d2, *wins = NULL; Window d1, d2, *wins = NULL;
2323 2391 unsigned int no; unsigned int no;
2392 int i;
2324 2393 XQueryTree(dpy,root,&d1,&d2,&wins,&no); XQueryTree(dpy,root,&d1,&d2,&wins,&no);
2325 2394 struct win *t; struct win *t;
2326 2395 printf("euclid-wm: %d windows\n",no); printf("euclid-wm: %d windows\n",no);
 
... ... int main() {
2330 2399 XWindowAttributes att; XWindowAttributes att;
2331 2400 XGetWindowAttributes(dpy,wins[i],&att); XGetWindowAttributes(dpy,wins[i],&att);
2332 2401 if (att.map_state != IsUnmapped) { if (att.map_state != IsUnmapped) {
2333 add_client_to_view(t,cv);
2402 add_client_to_view(t,cs->v);
2334 2403 }; };
2335 2404 //to see how to check for iconified windows, look at scrotwm getstate( //to see how to check for iconified windows, look at scrotwm getstate(
2336 2405 }; };
 
... ... int main() {
2345 2414 }; };
2346 2415 XSync(dpy,False); XSync(dpy,False);
2347 2416
2348 //make the stack window:
2349 stackid = XCreateSimpleWindow(dpy,root,0,(scrn_h-15),scrn_w,15,1,stack_unfocus_pix,stack_background_pix);
2350 XSetWindowAttributes att;
2351 att.override_redirect = true;
2352 XChangeWindowAttributes(dpy,stackid,CWOverrideRedirect,&att);
2353 XMapWindow(dpy,stackid);
2354 XSync(dpy,False);
2355 2417
2356 2418 XGCValues xgcv; XGCValues xgcv;
2357 2419 xgcv.foreground = stack_focus_pix; xgcv.foreground = stack_focus_pix;
2358 focus_gc = XCreateGC(dpy,stackid,GCForeground,&xgcv);
2420 focus_gc = XCreateGC(dpy,cs->stackid,GCForeground,&xgcv);
2359 2421 xgcv.foreground = stack_unfocus_pix; xgcv.foreground = stack_unfocus_pix;
2360 unfocus_gc = XCreateGC(dpy,stackid,GCForeground,&xgcv);
2422 unfocus_gc = XCreateGC(dpy,cs->stackid,GCForeground,&xgcv);
2361 2423
2362 2424 layout(); layout();
2363 2425
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/euclid-wm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/euclid-wm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master