tag.c
changeset 949 99ee5c370f94
parent 946 b938876de936
child 950 ebf2363d95f9
equal deleted inserted replaced
948:4d9c86f8ed65 949:99ee5c370f94
     1 /* See LICENSE file for copyright and license details. */
     1 /* See LICENSE file for copyright and license details. */
     2 #include "dwm.h"
     2 #include "dwm.h"
     3 #include <regex.h>
     3 #include <regex.h>
     4 #include <stdio.h>
     4 #include <stdio.h>
     5 #include <stdlib.h>
     5 #include <stdlib.h>
       
     6 #include <string.h>
       
     7 #include <X11/Xatom.h>
     6 #include <X11/Xutil.h>
     8 #include <X11/Xutil.h>
     7 
     9 
     8 /* static */
    10 /* static */
     9 
    11 
    10 typedef struct {
    12 typedef struct {
    21 TAGS
    23 TAGS
    22 RULES
    24 RULES
    23 
    25 
    24 static Regs *regs = NULL;
    26 static Regs *regs = NULL;
    25 static unsigned int nrules = 0;
    27 static unsigned int nrules = 0;
       
    28 static char prop[512];
    26 
    29 
    27 /* extern */
    30 /* extern */
    28 
    31 
    29 void
    32 void
    30 compileregs(void) {
    33 compileregs(void) {
    63 	return False;
    66 	return False;
    64 }
    67 }
    65 
    68 
    66 void
    69 void
    67 settags(Client *c, Client *trans) {
    70 settags(Client *c, Client *trans) {
    68 	char prop[512];
       
    69 	unsigned int i, j;
    71 	unsigned int i, j;
    70 	regmatch_t tmp;
    72 	regmatch_t tmp;
    71 	Bool matched = trans != NULL;
    73 	Bool matched = trans != NULL;
    72 	XClassHint ch = { 0 };
    74 	XClassHint ch = { 0 };
       
    75 	XTextProperty name;
    73 
    76 
    74 	if(matched)
    77 	if(matched) {
    75 		for(i = 0; i < ntags; i++)
    78 		for(i = 0; i < ntags; i++)
    76 			c->tags[i] = trans->tags[i];
    79 			c->tags[i] = trans->tags[i];
       
    80 		return;
       
    81 	}
    77 	else {
    82 	else {
       
    83 		/* check if window has set a property */
       
    84 		name.nitems = 0;
       
    85 		XGetTextProperty(dpy, c->win, &name, dwmtags);
       
    86 		if(name.nitems && name.encoding == XA_STRING) {
       
    87 			strncpy(prop, (char *)name.value, sizeof prop - 1);
       
    88 			prop[sizeof prop - 1] = '\0';
       
    89 			XFree(name.value);
       
    90 			for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
       
    91 				if((c->tags[i] = prop[i] == '+'))
       
    92 					matched = True;
       
    93 		}
       
    94 		if(matched)
       
    95 			return;
       
    96 		/* rule matching */
    78 		XGetClassHint(dpy, c->win, &ch);
    97 		XGetClassHint(dpy, c->win, &ch);
    79 		snprintf(prop, sizeof prop, "%s:%s:%s",
    98 		snprintf(prop, sizeof prop, "%s:%s:%s",
    80 				ch.res_class ? ch.res_class : "",
    99 				ch.res_class ? ch.res_class : "",
    81 				ch.res_name ? ch.res_name : "", c->name);
   100 				ch.res_name ? ch.res_name : "", c->name);
    82 		for(i = 0; i < nrules; i++)
   101 		for(i = 0; i < nrules; i++)
   108 	for(i = 0; i < ntags; i++)
   127 	for(i = 0; i < ntags; i++)
   109 		sel->tags[i] = arg == NULL;
   128 		sel->tags[i] = arg == NULL;
   110 	i = arg ? atoi(arg) : 0;
   129 	i = arg ? atoi(arg) : 0;
   111 	if(i >= 0 && i < ntags)
   130 	if(i >= 0 && i < ntags)
   112 		sel->tags[i] = True;
   131 		sel->tags[i] = True;
       
   132 	if(sel) {
       
   133 		for(i = 0; i < ntags && i < sizeof prop - 1; i++)
       
   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 	}
   113 	arrange();
   138 	arrange();
   114 }
   139 }
   115 
   140 
   116 void
   141 void
   117 toggletag(const char *arg) {
   142 toggletag(const char *arg) {