tag.c
changeset 950 ebf2363d95f9
parent 949 99ee5c370f94
child 953 d7de5c7bdbe4
equal deleted inserted replaced
949:99ee5c370f94 950:ebf2363d95f9
    24 RULES
    24 RULES
    25 
    25 
    26 static Regs *regs = NULL;
    26 static Regs *regs = NULL;
    27 static unsigned int nrules = 0;
    27 static unsigned int nrules = 0;
    28 static char prop[512];
    28 static char prop[512];
       
    29 
       
    30 static void
       
    31 persisttags(Client *c)
       
    32 {
       
    33 	unsigned int i;
       
    34 
       
    35 	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
       
    36 		prop[i] = c->tags[i] ? '+' : '-';
       
    37 	prop[i] = '\0';
       
    38 	XChangeProperty(dpy, c->win, dwmtags, XA_STRING, 8,
       
    39 			PropModeReplace, (unsigned char *)prop, i);
       
    40 }
    29 
    41 
    30 /* extern */
    42 /* extern */
    31 
    43 
    32 void
    44 void
    33 compileregs(void) {
    45 compileregs(void) {
    75 	XTextProperty name;
    87 	XTextProperty name;
    76 
    88 
    77 	if(matched) {
    89 	if(matched) {
    78 		for(i = 0; i < ntags; i++)
    90 		for(i = 0; i < ntags; i++)
    79 			c->tags[i] = trans->tags[i];
    91 			c->tags[i] = trans->tags[i];
    80 		return;
       
    81 	}
    92 	}
    82 	else {
    93 	else {
    83 		/* check if window has set a property */
    94 		/* check if window has set a property */
    84 		name.nitems = 0;
    95 		name.nitems = 0;
    85 		XGetTextProperty(dpy, c->win, &name, dwmtags);
    96 		XGetTextProperty(dpy, c->win, &name, dwmtags);
    89 			XFree(name.value);
   100 			XFree(name.value);
    90 			for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
   101 			for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
    91 				if((c->tags[i] = prop[i] == '+'))
   102 				if((c->tags[i] = prop[i] == '+'))
    92 					matched = True;
   103 					matched = True;
    93 		}
   104 		}
    94 		if(matched)
   105 	}
    95 			return;
   106 	if(!matched) {
    96 		/* rule matching */
   107 		/* rule matching */
    97 		XGetClassHint(dpy, c->win, &ch);
   108 		XGetClassHint(dpy, c->win, &ch);
    98 		snprintf(prop, sizeof prop, "%s:%s:%s",
   109 		snprintf(prop, sizeof prop, "%s:%s:%s",
    99 				ch.res_class ? ch.res_class : "",
   110 				ch.res_class ? ch.res_class : "",
   100 				ch.res_name ? ch.res_name : "", c->name);
   111 				ch.res_name ? ch.res_name : "", c->name);
   114 			XFree(ch.res_name);
   125 			XFree(ch.res_name);
   115 	}
   126 	}
   116 	if(!matched)
   127 	if(!matched)
   117 		for(i = 0; i < ntags; i++)
   128 		for(i = 0; i < ntags; i++)
   118 			c->tags[i] = seltag[i];
   129 			c->tags[i] = seltag[i];
       
   130 	persisttags(c);
   119 }
   131 }
   120 
   132 
   121 void
   133 void
   122 tag(const char *arg) {
   134 tag(const char *arg) {
   123 	int i;
   135 	int i;
   127 	for(i = 0; i < ntags; i++)
   139 	for(i = 0; i < ntags; i++)
   128 		sel->tags[i] = arg == NULL;
   140 		sel->tags[i] = arg == NULL;
   129 	i = arg ? atoi(arg) : 0;
   141 	i = arg ? atoi(arg) : 0;
   130 	if(i >= 0 && i < ntags)
   142 	if(i >= 0 && i < ntags)
   131 		sel->tags[i] = True;
   143 		sel->tags[i] = True;
   132 	if(sel) {
   144 	if(sel)
   133 		for(i = 0; i < ntags && i < sizeof prop - 1; i++)
   145 		persisttags(sel);
   134 			prop[i] = sel->tags[i] ? '+' : '-';
       
   135 		prop[i] = '\0';
       
   136 		XChangeProperty(dpy, sel->win, dwmtags, XA_STRING, 8, PropModeReplace, (unsigned char *)prop, i);
       
   137 	}
       
   138 	arrange();
   146 	arrange();
   139 }
   147 }
   140 
   148 
   141 void
   149 void
   142 toggletag(const char *arg) {
   150 toggletag(const char *arg) {
   147 	i = arg ? atoi(arg) : 0;
   155 	i = arg ? atoi(arg) : 0;
   148 	sel->tags[i] = !sel->tags[i];
   156 	sel->tags[i] = !sel->tags[i];
   149 	for(j = 0; j < ntags && !sel->tags[j]; j++);
   157 	for(j = 0; j < ntags && !sel->tags[j]; j++);
   150 	if(j == ntags)
   158 	if(j == ntags)
   151 		sel->tags[i] = True;
   159 		sel->tags[i] = True;
       
   160 	if(sel)
       
   161 		persisttags(sel);
   152 	arrange();
   162 	arrange();
   153 }
   163 }
   154 
   164 
   155 void
   165 void
   156 toggleview(const char *arg) {
   166 toggleview(const char *arg) {