static void frame_callback(void *data, struct wl_callback *callback, uint32_t time) { struct resizor *resizor = data; assert(!callback || callback == resizor->frame_callback); if (resizor->frame_callback) { wl_callback_destroy(resizor->frame_callback); resizor->frame_callback = NULL; } if (window_is_maximized(resizor->window)) return; spring_update(&resizor->width); spring_update(&resizor->height); widget_schedule_resize(resizor->widget, resizor->width.current + 0.5, resizor->height.current + 0.5); if (!spring_done(&resizor->width) || !spring_done(&resizor->height)) { resizor->frame_callback = wl_surface_frame( window_get_wl_surface(resizor->window)); wl_callback_add_listener(resizor->frame_callback, &listener, resizor); } }
static void set_window_background_colour(cairo_t *cr, struct window *window) { if (window_get_parent(window)) cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 0.4); else if (window_is_maximized(window)) cairo_set_source_rgba(cr, 1.0, 1.0, 0.0, 0.6); else if (window_is_fullscreen(window)) cairo_set_source_rgba(cr, 0.0, 1.0, 1.0, 0.6); else cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); }
static void key_handler(struct window *window, struct input *input, uint32_t time, uint32_t key, uint32_t sym, enum wl_keyboard_key_state state, void *data) { struct stacking *stacking = data; if (state != WL_KEYBOARD_KEY_STATE_PRESSED) return; switch (sym) { case XKB_KEY_f: fullscreen_handler(window, data); break; case XKB_KEY_m: window_set_maximized(window, !window_is_maximized(window)); break; case XKB_KEY_n: /* New top-level window. */ new_window(stacking, NULL); break; case XKB_KEY_p: show_popup(stacking, input, time, window); break; case XKB_KEY_q: exit (0); break; case XKB_KEY_t: /* New transient window. */ new_window(stacking, window); break; default: break; } }
static void redraw_handler(struct widget *widget, void *data) { struct window *window; struct rectangle allocation; cairo_t *cr; widget_get_allocation(widget, &allocation); window = widget_get_user_data(widget); cr = widget_cairo_create(widget); cairo_translate(cr, allocation.x, allocation.y); /* Draw background. */ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); set_window_background_colour(cr, window); cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_fill(cr); /* Print the instructions. */ cairo_move_to(cr, 5, 15); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); draw_string(cr, "Window: %p\n" "Fullscreen? %u\n" "Maximized? %u\n" "Transient? %u\n" "Keys: (f)ullscreen, (m)aximize,\n" " (n)ew window, (p)opup,\n" " (q)uit, (t)ransient window\n", window, window_is_fullscreen(window), window_is_maximized(window), window_get_parent(window) ? 1 : 0); cairo_destroy(cr); }
DECLARE_TEST( window, sizemove ) { window_t* window; #if FOUNDATION_PLATFORM_MACOSX window = window_allocate_from_nswindow( delegate_nswindow() ); #elif FOUNDATION_PLATFORM_IOS window = window_allocate_from_uiwindow( delegate_uiwindow() ); #endif EXPECT_NE( window, 0 ); EXPECT_TRUE( window_is_open( window ) ); thread_sleep( 1000 ); #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID EXPECT_TRUE( window_is_maximized( window ) ); #else EXPECT_FALSE( window_is_maximized( window ) ); #endif EXPECT_TRUE( window_is_visible( window ) ); EXPECT_TRUE( window_has_focus( window ) ); window_maximize( window ); thread_sleep( 1000 ); EXPECT_TRUE( window_is_maximized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); #if !FOUNDATION_PLATFORM_IOS && !FOUNDATION_PLATFORM_ANDROID window_restore( window ); thread_sleep( 1000 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); #endif window_maximize( window ); thread_sleep( 1000 ); EXPECT_TRUE( window_is_maximized( window ) ); #if !FOUNDATION_PLATFORM_IOS && !FOUNDATION_PLATFORM_ANDROID window_resize( window, 150, 100 ); thread_sleep( 1000 ); EXPECT_EQ( window_width( window ), 150 ); EXPECT_EQ( window_height( window ), 100 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); window_move( window, 10, 20 ); thread_sleep( 1000 ); EXPECT_EQ( window_position_x( window ), 10 ); EXPECT_EQ( window_position_y( window ), 20 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); window_minimize( window ); thread_sleep( 1000 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_FALSE( window_has_focus( window ) ); window_restore( window ); thread_sleep( 1000 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_FALSE( window_is_minimized( window ) ); EXPECT_TRUE( window_has_focus( window ) ); window_minimize( window ); thread_sleep( 1000 ); EXPECT_FALSE( window_is_maximized( window ) ); EXPECT_TRUE( window_is_minimized( window ) ); #endif window_deallocate( window ); window = 0; EXPECT_FALSE( window_is_open( window ) ); return 0; }