987 } 988 989 if (size_assigned && w <= 1 && h <= 1 && (geometry.final_width.value > 1 || 990 geometry.final_height.value > 1)) { 991 // skip artifact 992 return; 993 } 994 995 geometry.final_width.value = w; 996 geometry.final_width.type = BOUNDSTYPE_CONTENT; 997 geometry.final_height.value = h; 998 geometry.final_height.type = BOUNDSTYPE_CONTENT; 999 geometry_set_window_x(&geometry, x); 1000 geometry_set_window_y(&geometry, y); 1001 1002 if (jview) { 1003 mainEnv->CallVoidMethod(jview, jViewNotifyResize, 1004 event->width, 1005 event->height); 1006 CHECK_JNI_EXCEPTION(mainEnv) 1007 } 1008 if (jwindow) { 1009 mainEnv->CallVoidMethod(jwindow, jWindowNotifyResize, 1010 (is_maximized) 1011 ? com_sun_glass_events_WindowEvent_MAXIMIZE 1012 : com_sun_glass_events_WindowEvent_RESIZE, 1013 geometry.current_width, 1014 geometry.current_height); 1015 CHECK_JNI_EXCEPTION(mainEnv) 1016 1017 mainEnv->CallVoidMethod(jwindow, jWindowNotifyMove, x, y); 1018 CHECK_JNI_EXCEPTION(mainEnv) 1019 } 1020 1021 glong to_screen = getScreenPtrForLocation(x, y); 1022 if (to_screen != -1) { 1023 if (to_screen != screen) { 1024 if (jwindow) { 1025 //notify screen changed 1026 jobject jScreen = createJavaScreen(mainEnv, to_screen); 1037 } else if (!resizable.value) { 1038 set_window_resizable(false); 1039 } else if (updateWindowConstraints) { 1040 update_window_constraints(); 1041 } 1042 } 1043 1044 void WindowContextTop::update_window_constraints() { 1045 if (resizable.value) { 1046 GdkGeometry geom = { 1047 (resizable.minw == -1) ? 1 1048 : resizable.minw - geometry.extents.left - geometry.extents.right, 1049 (resizable.minh == -1) ? 1 1050 : resizable.minh - geometry.extents.top - geometry.extents.bottom, 1051 (resizable.maxw == -1) ? 100000 1052 : resizable.maxw - geometry.extents.left - geometry.extents.right, 1053 (resizable.maxh == -1) ? 100000 1054 : resizable.maxh - geometry.extents.top - geometry.extents.bottom, 1055 0, 0, 0, 0, 0.0, 0.0, GDK_GRAVITY_NORTH_WEST 1056 }; 1057 gdk_window_set_geometry_hints(gdk_window, &geom, 1058 static_cast<GdkWindowHints> (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE)); 1059 } 1060 } 1061 1062 void WindowContextTop::set_window_resizable(bool res) { 1063 if(!res) { 1064 int w = geometry_get_content_width(&geometry); 1065 int h = geometry_get_content_height(&geometry); 1066 if (w == -1 && h == -1) { 1067 gtk_window_get_size(GTK_WINDOW(gtk_widget), &w, &h); 1068 } 1069 GdkGeometry geom = {w, h, w, h, 0, 0, 0, 0, 0.0, 0.0, GDK_GRAVITY_NORTH_WEST}; 1070 gdk_window_set_geometry_hints(gdk_window, &geom, 1071 static_cast<GdkWindowHints>(GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE)); 1072 resizable.value = false; 1073 } else { 1074 resizable.value = true; 1075 update_window_constraints(); 1076 } 1077 } 1078 1079 void WindowContextTop::set_resizable(bool res) { 1080 resizable.prev = false; 1081 gint w, h; 1082 gtk_window_get_size(GTK_WINDOW(gtk_widget), &w, &h); 1083 if (map_received || w > 1 || h > 1) { 1084 set_window_resizable(res); 1085 } else { 1086 //Since window is not ready yet set only request for change of resizable. 1087 resizable.request = res ? REQUEST_RESIZABLE : REQUEST_NOT_RESIZABLE; 1088 } 1089 } 1090 1164 void WindowContextTop::process_map() { 1165 map_received = true; 1166 } 1167 1168 void WindowContextTop::window_configure(XWindowChanges *windowChanges, 1169 unsigned int windowChangesMask) { 1170 if (windowChangesMask == 0) { 1171 return; 1172 } 1173 1174 if (windowChangesMask & (CWX | CWY)) { 1175 gint newX, newY; 1176 gtk_window_get_position(GTK_WINDOW(gtk_widget), &newX, &newY); 1177 1178 if (windowChangesMask & CWX) { 1179 newX = windowChanges->x; 1180 } 1181 if (windowChangesMask & CWY) { 1182 newY = windowChanges->y; 1183 } 1184 1185 gdk_window_move(gdk_window, newX, newY); 1186 } 1187 1188 if (windowChangesMask & (CWWidth | CWHeight)) { 1189 gint newWidth, newHeight; 1190 gtk_window_get_size(GTK_WINDOW(gtk_widget), &newWidth, &newHeight); 1191 1192 if (windowChangesMask & CWWidth) { 1193 newWidth = windowChanges->width; 1194 } 1195 if (windowChangesMask & CWHeight) { 1196 newHeight = windowChanges->height; 1197 } 1198 1199 if (!resizable.value) { 1200 GdkGeometry geom; 1201 GdkWindowHints hints = (GdkWindowHints)(GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); 1202 geom.min_width = geom.max_width = newWidth; 1203 geom.min_height = geom.max_height = newHeight; 1204 gdk_window_set_geometry_hints(gdk_window, &geom, hints); 1205 } 1206 gdk_window_resize(gdk_window, newWidth, newHeight); 1207 } 1208 } 1209 1210 void WindowContextTop::applyShapeMask(void* data, uint width, uint height) 1211 { 1212 if (frame_type != TRANSPARENT) { 1213 return; 1214 } 1215 1216 glass_window_apply_shape_mask(gtk_widget_get_window(gtk_widget), data, width, height); 1217 } 1218 1219 void WindowContextTop::set_minimized(bool minimize) { 1220 is_iconified = minimize; 1221 if (minimize) { 1222 if (frame_type == TRANSPARENT) { 1223 // https://bugs.launchpad.net/ubuntu/+source/unity/+bug/1245571 1224 glass_window_reset_input_shape_mask(gtk_widget_get_window(gtk_widget)); 1225 } 1226 1227 if ((gdk_windowManagerFunctions & GDK_FUNC_MINIMIZE) == 0) { 1228 // in this case - the window manager will not support the programatic 1229 // request to iconify - so we need to disable this until we are restored. 1230 GdkWMFunction wmf = (GdkWMFunction)(gdk_windowManagerFunctions | GDK_FUNC_MINIMIZE); 1231 gdk_window_set_functions(gdk_window, wmf); 1232 } 1233 gtk_window_iconify(GTK_WINDOW(gtk_widget)); 1234 } else { 1235 gtk_window_deiconify(GTK_WINDOW(gtk_widget)); 1236 activate_window(); 1237 } 1238 } 1239 void WindowContextTop::set_maximized(bool maximize) { 1240 is_maximized = maximize; 1241 if (maximize) { 1242 gtk_window_maximize(GTK_WINDOW(gtk_widget)); 1243 } else { 1244 gtk_window_unmaximize(GTK_WINDOW(gtk_widget)); 1245 } 1246 } 1247 1248 void WindowContextTop::enter_fullscreen() { 1249 gtk_window_fullscreen(GTK_WINDOW(gtk_widget)); 1250 } 1251 1252 void WindowContextTop::exit_fullscreen() { 1253 gtk_window_unfullscreen(GTK_WINDOW(gtk_widget)); 1254 } 1255 1256 void WindowContextTop::request_focus() { 1257 gtk_window_present(GTK_WINDOW(gtk_widget)); 1258 } 1259 1260 void WindowContextTop::set_focusable(bool focusable) { 1261 gtk_window_set_accept_focus(GTK_WINDOW(gtk_widget), focusable ? TRUE : FALSE); 1262 } 1263 1264 void WindowContextTop::set_title(const char* title) { 1265 gtk_window_set_title(GTK_WINDOW(gtk_widget),title); 1266 } 1267 1268 void WindowContextTop::set_alpha(double alpha) { | 987 } 988 989 if (size_assigned && w <= 1 && h <= 1 && (geometry.final_width.value > 1 || 990 geometry.final_height.value > 1)) { 991 // skip artifact 992 return; 993 } 994 995 geometry.final_width.value = w; 996 geometry.final_width.type = BOUNDSTYPE_CONTENT; 997 geometry.final_height.value = h; 998 geometry.final_height.type = BOUNDSTYPE_CONTENT; 999 geometry_set_window_x(&geometry, x); 1000 geometry_set_window_y(&geometry, y); 1001 1002 if (jview) { 1003 mainEnv->CallVoidMethod(jview, jViewNotifyResize, 1004 event->width, 1005 event->height); 1006 CHECK_JNI_EXCEPTION(mainEnv) 1007 mainEnv->CallVoidMethod(jview, jViewNotifyView, 1008 com_sun_glass_events_ViewEvent_MOVE); 1009 CHECK_JNI_EXCEPTION(mainEnv) 1010 } 1011 if (jwindow) { 1012 mainEnv->CallVoidMethod(jwindow, jWindowNotifyResize, 1013 (is_maximized) 1014 ? com_sun_glass_events_WindowEvent_MAXIMIZE 1015 : com_sun_glass_events_WindowEvent_RESIZE, 1016 geometry.current_width, 1017 geometry.current_height); 1018 CHECK_JNI_EXCEPTION(mainEnv) 1019 1020 mainEnv->CallVoidMethod(jwindow, jWindowNotifyMove, x, y); 1021 CHECK_JNI_EXCEPTION(mainEnv) 1022 } 1023 1024 glong to_screen = getScreenPtrForLocation(x, y); 1025 if (to_screen != -1) { 1026 if (to_screen != screen) { 1027 if (jwindow) { 1028 //notify screen changed 1029 jobject jScreen = createJavaScreen(mainEnv, to_screen); 1040 } else if (!resizable.value) { 1041 set_window_resizable(false); 1042 } else if (updateWindowConstraints) { 1043 update_window_constraints(); 1044 } 1045 } 1046 1047 void WindowContextTop::update_window_constraints() { 1048 if (resizable.value) { 1049 GdkGeometry geom = { 1050 (resizable.minw == -1) ? 1 1051 : resizable.minw - geometry.extents.left - geometry.extents.right, 1052 (resizable.minh == -1) ? 1 1053 : resizable.minh - geometry.extents.top - geometry.extents.bottom, 1054 (resizable.maxw == -1) ? 100000 1055 : resizable.maxw - geometry.extents.left - geometry.extents.right, 1056 (resizable.maxh == -1) ? 100000 1057 : resizable.maxh - geometry.extents.top - geometry.extents.bottom, 1058 0, 0, 0, 0, 0.0, 0.0, GDK_GRAVITY_NORTH_WEST 1059 }; 1060 gtk_window_set_geometry_hints(GTK_WINDOW(gtk_widget), NULL, &geom, 1061 static_cast<GdkWindowHints> (GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE)); 1062 } 1063 } 1064 1065 void WindowContextTop::set_window_resizable(bool res) { 1066 if(!res) { 1067 int w = geometry_get_content_width(&geometry); 1068 int h = geometry_get_content_height(&geometry); 1069 if (w == -1 && h == -1) { 1070 gtk_window_get_size(GTK_WINDOW(gtk_widget), &w, &h); 1071 } 1072 GdkGeometry geom = {w, h, w, h, 0, 0, 0, 0, 0.0, 0.0, GDK_GRAVITY_NORTH_WEST}; 1073 gtk_window_set_geometry_hints(GTK_WINDOW(gtk_widget), NULL, &geom, 1074 static_cast<GdkWindowHints>(GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE)); 1075 resizable.value = false; 1076 } else { 1077 resizable.value = true; 1078 update_window_constraints(); 1079 } 1080 } 1081 1082 void WindowContextTop::set_resizable(bool res) { 1083 resizable.prev = false; 1084 gint w, h; 1085 gtk_window_get_size(GTK_WINDOW(gtk_widget), &w, &h); 1086 if (map_received || w > 1 || h > 1) { 1087 set_window_resizable(res); 1088 } else { 1089 //Since window is not ready yet set only request for change of resizable. 1090 resizable.request = res ? REQUEST_RESIZABLE : REQUEST_NOT_RESIZABLE; 1091 } 1092 } 1093 1167 void WindowContextTop::process_map() { 1168 map_received = true; 1169 } 1170 1171 void WindowContextTop::window_configure(XWindowChanges *windowChanges, 1172 unsigned int windowChangesMask) { 1173 if (windowChangesMask == 0) { 1174 return; 1175 } 1176 1177 if (windowChangesMask & (CWX | CWY)) { 1178 gint newX, newY; 1179 gtk_window_get_position(GTK_WINDOW(gtk_widget), &newX, &newY); 1180 1181 if (windowChangesMask & CWX) { 1182 newX = windowChanges->x; 1183 } 1184 if (windowChangesMask & CWY) { 1185 newY = windowChanges->y; 1186 } 1187 gtk_window_move(GTK_WINDOW(gtk_widget), newX, newY); 1188 } 1189 1190 if (windowChangesMask & (CWWidth | CWHeight)) { 1191 gint newWidth, newHeight; 1192 gtk_window_get_size(GTK_WINDOW(gtk_widget), &newWidth, &newHeight); 1193 1194 if (windowChangesMask & CWWidth) { 1195 newWidth = windowChanges->width; 1196 } 1197 if (windowChangesMask & CWHeight) { 1198 newHeight = windowChanges->height; 1199 } 1200 1201 if (!resizable.value) { 1202 GdkGeometry geom; 1203 GdkWindowHints hints = (GdkWindowHints)(GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); 1204 geom.min_width = geom.max_width = newWidth; 1205 geom.min_height = geom.max_height = newHeight; 1206 gtk_window_set_geometry_hints(GTK_WINDOW(gtk_widget), NULL, &geom, hints); 1207 } 1208 gtk_window_resize(GTK_WINDOW(gtk_widget), newWidth, newHeight); 1209 } 1210 } 1211 1212 void WindowContextTop::applyShapeMask(void* data, uint width, uint height) 1213 { 1214 if (frame_type != TRANSPARENT) { 1215 return; 1216 } 1217 1218 glass_window_apply_shape_mask(gtk_widget_get_window(gtk_widget), data, width, height); 1219 } 1220 1221 void WindowContextTop::ensure_window_size() { 1222 gint w, h; 1223 #ifdef GLASS_GTK3 1224 gdk_window_get_geometry(gdk_window, NULL, NULL, &w, &h); 1225 #else 1226 gdk_window_get_geometry(gdk_window, NULL, NULL, &w, &h, NULL); 1227 #endif 1228 if (size_assigned && (geometry.final_width.value != w 1229 || geometry.final_height.value != h)) { 1230 1231 gdk_window_resize(gdk_window, geometry.final_width.value, 1232 geometry.final_height.value); 1233 } 1234 } 1235 1236 void WindowContextTop::set_minimized(bool minimize) { 1237 is_iconified = minimize; 1238 if (minimize) { 1239 if (frame_type == TRANSPARENT) { 1240 // https://bugs.launchpad.net/ubuntu/+source/unity/+bug/1245571 1241 glass_window_reset_input_shape_mask(gtk_widget_get_window(gtk_widget)); 1242 } 1243 1244 if ((gdk_windowManagerFunctions & GDK_FUNC_MINIMIZE) == 0) { 1245 // in this case - the window manager will not support the programatic 1246 // request to iconify - so we need to disable this until we are restored. 1247 GdkWMFunction wmf = (GdkWMFunction)(gdk_windowManagerFunctions | GDK_FUNC_MINIMIZE); 1248 gdk_window_set_functions(gdk_window, wmf); 1249 } 1250 gtk_window_iconify(GTK_WINDOW(gtk_widget)); 1251 } else { 1252 gtk_window_deiconify(GTK_WINDOW(gtk_widget)); 1253 activate_window(); 1254 } 1255 } 1256 void WindowContextTop::set_maximized(bool maximize) { 1257 is_maximized = maximize; 1258 if (maximize) { 1259 ensure_window_size(); 1260 gtk_window_maximize(GTK_WINDOW(gtk_widget)); 1261 } else { 1262 gtk_window_unmaximize(GTK_WINDOW(gtk_widget)); 1263 } 1264 } 1265 1266 void WindowContextTop::enter_fullscreen() { 1267 ensure_window_size(); 1268 gtk_window_fullscreen(GTK_WINDOW(gtk_widget)); 1269 } 1270 1271 void WindowContextTop::exit_fullscreen() { 1272 gtk_window_unfullscreen(GTK_WINDOW(gtk_widget)); 1273 } 1274 1275 void WindowContextTop::request_focus() { 1276 gtk_window_present(GTK_WINDOW(gtk_widget)); 1277 } 1278 1279 void WindowContextTop::set_focusable(bool focusable) { 1280 gtk_window_set_accept_focus(GTK_WINDOW(gtk_widget), focusable ? TRUE : FALSE); 1281 } 1282 1283 void WindowContextTop::set_title(const char* title) { 1284 gtk_window_set_title(GTK_WINDOW(gtk_widget),title); 1285 } 1286 1287 void WindowContextTop::set_alpha(double alpha) { |