diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/graphics/sprite.c | 16 | ||||
-rw-r--r-- | src/window/window.c | 39 |
2 files changed, 54 insertions, 1 deletions
diff --git a/src/graphics/sprite.c b/src/graphics/sprite.c index df3e902..95f733b 100644 --- a/src/graphics/sprite.c +++ b/src/graphics/sprite.c @@ -31,6 +31,22 @@ void mgl_sprite_set_origin(mgl_sprite *self, mgl_vec2f origin) { self->origin = origin; } +void mgl_sprite_set_size(mgl_sprite *self, mgl_vec2f size) { + if(!self->texture) + return; + + self->scale.x = size.x / (float)self->texture->width; + self->scale.y = size.y / (float)self->texture->height; +} + +void mgl_sprite_set_height(mgl_sprite *self, float height) { + if(!self->texture) + return; + + self->scale.x = height / (float)self->texture->width; + self->scale.y = self->scale.x; +} + /* TODO: Cache texture bind to not bind texture if its already bound and do not bind texture 0 */ void mgl_sprite_draw(mgl_context *context, mgl_sprite *sprite) { if(!sprite->texture) diff --git a/src/window/window.c b/src/window/window.c index 17066a0..8681db9 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -76,6 +76,7 @@ typedef struct { Atom net_wm_window_type_atom; Atom net_wm_window_type_normal_atom; Atom net_wm_window_type_dialog_atom; + Atom motif_wm_hints_atom; Cursor default_cursor; Cursor invisible_cursor; unsigned int prev_keycode_pressed; @@ -156,6 +157,7 @@ static int x11_context_init(x11_context *self, bool alpha) { self->glx_context = NULL; self->xim = NULL; self->xic = NULL; + /* TODO: Create all of these with one XInternAtoms call instead */ self->clipboard_atom = XInternAtom(context->connection, "CLIPBOARD", False); self->targets_atom = XInternAtom(context->connection, "TARGETS", False); self->text_atom = XInternAtom(context->connection, "TEXT", False); @@ -172,6 +174,7 @@ static int x11_context_init(x11_context *self, bool alpha) { self->net_wm_window_type_atom = XInternAtom(context->connection, "_NET_WM_WINDOW_TYPE", False); self->net_wm_window_type_normal_atom = XInternAtom(context->connection, "_NET_WM_WINDOW_TYPE_NORMAL", False); self->net_wm_window_type_dialog_atom = XInternAtom(context->connection, "_NET_WM_WINDOW_TYPE_DIALOG", False); + self->motif_wm_hints_atom = XInternAtom(context->connection, "_MOTIF_WM_HINTS", False); self->default_cursor = None; self->invisible_cursor = None; @@ -501,6 +504,30 @@ static void mgl_set_window_type(mgl_window *self, mgl_window_type window_type) { } } +typedef struct { + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long input_mode; + unsigned long status; +} MotifHints; + +#define MWM_HINTS_DECORATIONS 2 + +#define MWM_DECOR_NONE 0 +#define MWM_DECOR_ALL 1 + +static void mgl_window_set_decorations_visible(mgl_window *self, bool visible) { + mgl_context *context = mgl_get_context(); + x11_context *x11_context = self->context; + + MotifHints motif_hints = {0}; + motif_hints.flags = MWM_HINTS_DECORATIONS; + motif_hints.decorations = visible ? MWM_DECOR_ALL : MWM_DECOR_NONE; + + XChangeProperty(context->connection, self->window, x11_context->motif_wm_hints_atom, x11_context->motif_wm_hints_atom, 32, PropModeReplace, (unsigned char*)&motif_hints, sizeof(motif_hints) / sizeof(long)); +} + static int mgl_window_init(mgl_window *self, const char *title, const mgl_window_create_params *params, Window existing_window) { self->window = 0; self->context = NULL; @@ -588,6 +615,11 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window } self->window = existing_window; + + if(params && params->hide_decorations) { + mgl_window_set_decorations_visible(self, false); + } + if(hide_window) XUnmapWindow(context->connection, existing_window); } else { @@ -601,6 +633,10 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window return -1; } + if(params && params->hide_decorations) { + mgl_window_set_decorations_visible(self, false); + } + mgl_window_set_title(self, title); if(!hide_window) XMapWindow(context->connection, self->window); @@ -625,7 +661,7 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window char host_name[HOST_NAME_MAX]; if(gethostname(host_name, sizeof(host_name)) == 0) { XTextProperty txt_prop; - txt_prop.value = host_name; + txt_prop.value = (unsigned char*)host_name; txt_prop.encoding = XA_STRING; txt_prop.format = 8; txt_prop.nitems = strlen(host_name); @@ -641,6 +677,7 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window XSetTransientForHint(context->connection, self->window, params->transient_for_window); } + /* TODO: Move this to above XMapWindow? */ mgl_window_type window_type = params ? params->window_type : MGL_WINDOW_TYPE_NORMAL; mgl_set_window_type(self, window_type); |