00001
00002
00003
00004
00005
00006
00007
00008 #include "all.h"
00009
00010
00011
00012
00013
00014
00015 void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
00016 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
00017 DLOG("empty property, not updating\n");
00018 FREE(prop);
00019 return;
00020 }
00021
00022
00023
00024
00025 char *new_class = xcb_get_property_value(prop);
00026
00027 FREE(win->class_instance);
00028 FREE(win->class_class);
00029
00030 win->class_instance = sstrdup(new_class);
00031 if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
00032 win->class_class = sstrdup(new_class + strlen(new_class) + 1);
00033 else win->class_class = NULL;
00034 LOG("WM_CLASS changed to %s (instance), %s (class)\n",
00035 win->class_instance, win->class_class);
00036
00037 if (before_mgmt) {
00038 free(prop);
00039 return;
00040 }
00041
00042 run_assignments(win);
00043
00044 free(prop);
00045 }
00046
00047
00048
00049
00050
00051
00052 void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
00053 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
00054 DLOG("_NET_WM_NAME not specified, not changing\n");
00055 FREE(prop);
00056 return;
00057 }
00058
00059
00060 char *new_name;
00061 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
00062 (char*)xcb_get_property_value(prop)) == -1) {
00063 perror("asprintf()");
00064 DLOG("Could not get window name\n");
00065 free(prop);
00066 return;
00067 }
00068
00069 int len;
00070 char *ucs2_name = convert_utf8_to_ucs2(new_name, &len);
00071 if (ucs2_name == NULL) {
00072 LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n");
00073 FREE(new_name);
00074 free(prop);
00075 return;
00076 }
00077 FREE(win->name_x);
00078 FREE(win->name_json);
00079 win->name_json = new_name;
00080 win->name_x = ucs2_name;
00081 win->name_len = len;
00082 win->name_x_changed = true;
00083 LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_json);
00084
00085 win->uses_net_wm_name = true;
00086
00087 if (before_mgmt) {
00088 free(prop);
00089 return;
00090 }
00091
00092 run_assignments(win);
00093
00094 free(prop);
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
00105 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
00106 DLOG("prop == NULL\n");
00107 FREE(prop);
00108 return;
00109 }
00110
00111
00112 if (win->uses_net_wm_name) {
00113 free(prop);
00114 return;
00115 }
00116
00117 char *new_name;
00118 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
00119 (char*)xcb_get_property_value(prop)) == -1) {
00120 perror("asprintf()");
00121 DLOG("Could not get legacy window name\n");
00122 free(prop);
00123 return;
00124 }
00125
00126 LOG("Using legacy window title. Note that in order to get Unicode window "
00127 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
00128
00129 FREE(win->name_x);
00130 FREE(win->name_json);
00131 win->name_x = new_name;
00132 win->name_json = sstrdup(new_name);
00133 win->name_len = strlen(new_name);
00134 win->name_x_changed = true;
00135
00136 if (before_mgmt) {
00137 free(prop);
00138 return;
00139 }
00140
00141 run_assignments(win);
00142
00143 free(prop);
00144 }
00145
00146
00147
00148
00149
00150 void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
00151 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
00152 DLOG("prop == NULL\n");
00153 FREE(prop);
00154 return;
00155 }
00156
00157 xcb_window_t *leader = xcb_get_property_value(prop);
00158 if (leader == NULL) {
00159 free(prop);
00160 return;
00161 }
00162
00163 DLOG("Client leader changed to %08x\n", *leader);
00164
00165 win->leader = *leader;
00166
00167 free(prop);
00168 }
00169
00170
00171
00172
00173
00174 void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
00175 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
00176 DLOG("prop == NULL\n");
00177 FREE(prop);
00178 return;
00179 }
00180
00181 xcb_window_t transient_for;
00182 if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop)) {
00183 free(prop);
00184 return;
00185 }
00186
00187 DLOG("Transient for changed to %08x\n", transient_for);
00188
00189 win->transient_for = transient_for;
00190
00191 free(prop);
00192 }
00193
00194
00195
00196
00197
00198 void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop) {
00199 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
00200 DLOG("prop == NULL\n");
00201 FREE(prop);
00202 return;
00203 }
00204
00205 uint32_t *strut;
00206 if (!(strut = xcb_get_property_value(prop))) {
00207 free(prop);
00208 return;
00209 }
00210
00211 DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
00212 strut[0], strut[1], strut[2], strut[3]);
00213
00214 win->reserved = (struct reservedpx){ strut[0], strut[1], strut[2], strut[3] };
00215
00216 free(prop);
00217 }