Experimental decorator menu stuff

This commit is contained in:
K. Lange 2018-04-27 22:14:08 +09:00 committed by Kevin Lange
parent 5129394b07
commit f8d2b8d3a3
3 changed files with 53 additions and 9 deletions

View File

@ -44,12 +44,14 @@ extern int decor_handle_event(yutani_t * yctx, yutani_msg_t * m);
extern void decor_set_close_callback(void (*callback)(yutani_window_t *));
extern void decor_set_resize_callback(void (*callback)(yutani_window_t *));
extern void decor_set_maximize_callback(void (*callback)(yutani_window_t *));
extern yutani_window_t * decor_show_default_menu(yutani_window_t * window, int y, int x);
/* Responses from handle_event */
#define DECOR_OTHER 1
#define DECOR_CLOSE 2
#define DECOR_RESIZE 3
#define DECOR_OTHER 1 /* Clicked on title bar but otherwise unimportant */
#define DECOR_CLOSE 2 /* Clicked on close button */
#define DECOR_RESIZE 3 /* Resize button */
#define DECOR_MAXIMIZE 4
#define DECOR_RIGHT 5
#define DECOR_ACTIVE 0
#define DECOR_INACTIVE 1

View File

@ -14,6 +14,7 @@
#include <toaru/yutani.h>
#include <toaru/decorations.h>
#include <toaru/sdf.h>
#include <toaru/menu.h>
uint32_t decor_top_height = 33;
uint32_t decor_bottom_height = 6;
@ -95,6 +96,7 @@ static void initialize_simple() {
void render_decorations(yutani_window_t * window, gfx_context_t * ctx, char * title) {
if (!window) return;
window->is_decorated = true;
if (!window->focused) {
decor_render_decorations(window, ctx, title, DECOR_INACTIVE);
} else {
@ -104,13 +106,53 @@ void render_decorations(yutani_window_t * window, gfx_context_t * ctx, char * ti
void render_decorations_inactive(yutani_window_t * window, gfx_context_t * ctx, char * title) {
if (!window) return;
window->is_decorated = true;
decor_render_decorations(window, ctx, title, DECOR_INACTIVE);
}
static void _decor_maximize(yutani_t * yctx, yutani_window_t * window) {
if (callback_maximize) {
callback_maximize(window);
} else {
fprintf(stderr, "bloop\n");
yutani_special_request(yctx, window, YUTANI_SPECIAL_REQUEST_MAXIMIZE);
}
}
static yutani_window_t * _decor_menu_owner_window = NULL;
static struct MenuList * _decor_menu = NULL;
static void _decor_start_move(struct MenuEntry * self) {
if (!_decor_menu_owner_window)
return;
yutani_focus_window(_decor_menu_owner_window->ctx, _decor_menu_owner_window->wid);
yutani_window_drag_start(_decor_menu_owner_window->ctx, _decor_menu_owner_window);
}
static void _decor_start_maximize(struct MenuEntry * self) {
if (!_decor_menu_owner_window)
return;
fprintf(stderr, "Sending maximize request\n");
_decor_maximize(_decor_menu_owner_window->ctx, _decor_menu_owner_window);
yutani_focus_window(_decor_menu_owner_window->ctx, _decor_menu_owner_window->wid);
}
yutani_window_t * decor_show_default_menu(yutani_window_t * window, int y, int x) {
if (_decor_menu->window) return NULL;
_decor_menu_owner_window = window;
menu_show(_decor_menu, window->ctx);
yutani_window_move(window->ctx, _decor_menu->window, y, x);
return _decor_menu->window;
}
void init_decorations() {
char * tmp = getenv("WM_THEME");
char * theme = tmp ? strdup(tmp) : NULL;
_decor_menu = menu_create();
menu_insert(_decor_menu, menu_create_normal(NULL, NULL, "Maximize", _decor_start_maximize));
menu_insert(_decor_menu, menu_create_normal(NULL, NULL, "Move", _decor_start_move));
if (!theme || !strcmp(theme, "simple")) {
initialize_simple();
} else {
@ -201,6 +243,7 @@ int decor_handle_event(yutani_t * yctx, yutani_msg_t * m) {
struct yutani_msg_window_mouse_event * me = (void*)m->data;
yutani_window_t * window = hashmap_get(yctx->windows, (void*)me->wid);
if (!window) return 0;
if (!window->is_decorated) return 0;
if (within_decors(window, me->new_x, me->new_y)) {
int button = decor_check_button_press(window, me->new_x, me->new_y);
if (me->command == YUTANI_MOUSE_EVENT_DOWN && me->buttons & YUTANI_MOUSE_BUTTON_LEFT) {
@ -218,6 +261,9 @@ int decor_handle_event(yutani_t * yctx, yutani_msg_t * m) {
return DECOR_OTHER;
}
}
if (!button && (me->buttons & YUTANI_MOUSE_BUTTON_RIGHT)) {
return DECOR_RIGHT;
}
if (me->command == YUTANI_MOUSE_EVENT_MOVE) {
if (!button) {
/* Resize edges */
@ -262,11 +308,7 @@ int decor_handle_event(yutani_t * yctx, yutani_msg_t * m) {
if (callback_resize) callback_resize(window);
break;
case DECOR_MAXIMIZE:
if (callback_maximize) {
callback_maximize(window);
} else {
yutani_special_request(yctx, window, YUTANI_SPECIAL_REQUEST_MAXIMIZE);
}
_decor_maximize(yctx, window);
break;
default:
break;

View File

@ -32,7 +32,7 @@ class Classifier(object):
'<toaru/confreader.h>': (None, '-ltoaru_confreader', ['<toaru/hashmap.h>']),
'<toaru/dlfcn.h>': (None, '-ltoaru_dlfcn', []),
'<toaru/yutani.h>': (None, '-ltoaru_yutani', ['<toaru/kbd.h>', '<toaru/list.h>', '<toaru/pex.h>', '<toaru/graphics.h>', '<toaru/hashmap.h>']),
'<toaru/decorations.h>': (None, '-ltoaru_decorations', ['<toaru/sdf.h>', '<toaru/graphics.h>', '<toaru/yutani.h>','<toaru/dlfcn.h>']),
'<toaru/decorations.h>': (None, '-ltoaru_decorations', ['<toaru/menu.h>', '<toaru/sdf.h>', '<toaru/graphics.h>', '<toaru/yutani.h>','<toaru/dlfcn.h>']),
'<toaru/termemu.h>': (None, '-ltoaru_termemu', ['<toaru/graphics.h>']),
'<toaru/sdf.h>': (None, '-ltoaru_sdf', ['<toaru/graphics.h>', '<toaru/hashmap.h>']),
'<toaru/icon_cache.h>': (None, '-ltoaru_icon_cache', ['<toaru/graphics.h>', '<toaru/hashmap.h>']),