tag.c
changeset 953 d7de5c7bdbe4
parent 950 ebf2363d95f9
child 954 18381a2cda42
equal deleted inserted replaced
952:4f66942cc63b 953:d7de5c7bdbe4
    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 
    29 
    30 static void
    30 static void
    31 persisttags(Client *c)
    31 persistconfig(Client *c) {
    32 {
       
    33 	unsigned int i;
    32 	unsigned int i;
    34 
    33 
    35 	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
    34 	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
    36 		prop[i] = c->tags[i] ? '+' : '-';
    35 		prop[i] = c->tags[i] ? '1' : '0';
       
    36 	if(i < sizeof prop - 1)
       
    37 		prop[i++] = c->isfloating ? '1' : '0';
    37 	prop[i] = '\0';
    38 	prop[i] = '\0';
    38 	XChangeProperty(dpy, c->win, dwmtags, XA_STRING, 8,
    39 	XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8,
    39 			PropModeReplace, (unsigned char *)prop, i);
    40 			PropModeReplace, (unsigned char *)prop, i);
    40 }
    41 }
    41 
    42 
    42 /* extern */
    43 /* extern */
    43 
    44 
    91 			c->tags[i] = trans->tags[i];
    92 			c->tags[i] = trans->tags[i];
    92 	}
    93 	}
    93 	else {
    94 	else {
    94 		/* check if window has set a property */
    95 		/* check if window has set a property */
    95 		name.nitems = 0;
    96 		name.nitems = 0;
    96 		XGetTextProperty(dpy, c->win, &name, dwmtags);
    97 		XGetTextProperty(dpy, c->win, &name, dwmconfig);
    97 		if(name.nitems && name.encoding == XA_STRING) {
    98 		if(name.nitems && name.encoding == XA_STRING) {
    98 			strncpy(prop, (char *)name.value, sizeof prop - 1);
    99 			strncpy(prop, (char *)name.value, sizeof prop - 1);
    99 			prop[sizeof prop - 1] = '\0';
   100 			prop[sizeof prop - 1] = '\0';
   100 			XFree(name.value);
   101 			XFree(name.value);
   101 			for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
   102 			for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
   102 				if((c->tags[i] = prop[i] == '+'))
   103 				if((c->tags[i] = prop[i] == '1'))
   103 					matched = True;
   104 					matched = True;
       
   105 			if(i < sizeof prop - 1 && prop[i] != '\0')
       
   106 				c->isfloating = prop[i] == '1';
   104 		}
   107 		}
   105 	}
   108 	}
   106 	if(!matched) {
   109 	if(!matched) {
   107 		/* rule matching */
   110 		/* rule matching */
   108 		XGetClassHint(dpy, c->win, &ch);
   111 		XGetClassHint(dpy, c->win, &ch);
   125 			XFree(ch.res_name);
   128 			XFree(ch.res_name);
   126 	}
   129 	}
   127 	if(!matched)
   130 	if(!matched)
   128 		for(i = 0; i < ntags; i++)
   131 		for(i = 0; i < ntags; i++)
   129 			c->tags[i] = seltag[i];
   132 			c->tags[i] = seltag[i];
   130 	persisttags(c);
   133 	persistconfig(c);
   131 }
   134 }
   132 
   135 
   133 void
   136 void
   134 tag(const char *arg) {
   137 tag(const char *arg) {
   135 	int i;
   138 	int i;
   140 		sel->tags[i] = arg == NULL;
   143 		sel->tags[i] = arg == NULL;
   141 	i = arg ? atoi(arg) : 0;
   144 	i = arg ? atoi(arg) : 0;
   142 	if(i >= 0 && i < ntags)
   145 	if(i >= 0 && i < ntags)
   143 		sel->tags[i] = True;
   146 		sel->tags[i] = True;
   144 	if(sel)
   147 	if(sel)
   145 		persisttags(sel);
   148 		persistconfig(sel);
       
   149 	arrange();
       
   150 }
       
   151 
       
   152 void
       
   153 togglefloating(const char *arg) {
       
   154 	if(!sel || isfloating())
       
   155 		return;
       
   156 	sel->isfloating = !sel->isfloating;
       
   157 	if(sel->isfloating)
       
   158 		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
   146 	arrange();
   159 	arrange();
   147 }
   160 }
   148 
   161 
   149 void
   162 void
   150 toggletag(const char *arg) {
   163 toggletag(const char *arg) {
   156 	sel->tags[i] = !sel->tags[i];
   169 	sel->tags[i] = !sel->tags[i];
   157 	for(j = 0; j < ntags && !sel->tags[j]; j++);
   170 	for(j = 0; j < ntags && !sel->tags[j]; j++);
   158 	if(j == ntags)
   171 	if(j == ntags)
   159 		sel->tags[i] = True;
   172 		sel->tags[i] = True;
   160 	if(sel)
   173 	if(sel)
   161 		persisttags(sel);
   174 		persistconfig(sel);
   162 	arrange();
   175 	arrange();
   163 }
   176 }
   164 
   177 
   165 void
   178 void
   166 toggleview(const char *arg) {
   179 toggleview(const char *arg) {