Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added decorations.(c/h) Files #284

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions decorations.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <stdlib.h>

#include "decorations.h"
#include "util.h"

#define _DECOR_FLAGS_PREFER_CSD_ (1 << 0)

Decoration *
X11DecorCreate(void)
{
Decoration *decor = malloc(sizeof(Decoration));
if(decor)
{
decor->w = 1;
decor->h = 1;
decor->win = 0;
decor->flags = 0;
}
return decor;
}

void
X11DecorHoldChild(Decoration *decor, XCBWindow child)
{
if(!decor)
{ return;
}
decor->child = child;
}

void
X11DecorMap(XCBDisplay *display, Decoration *decor)
{
if(!display || !decor)
{ return;
}
XCBMapWindow(display, decor->win);
}

void
X11DecorUnmap(XCBDisplay *display, Decoration *decor)
{
if(!display || !decor)
{ return;
}
XCBUnmapWindow(display, decor->win);
}

void
X11DecorSetPreferCSD(Decoration *decor, uint8_t state)
{
if(!decor)
{ return;
}
const char *const GTK_CSD = "GTK_CSD";
const char *const GTK_REPLACE = "1";

SETFLAG(decor->flags, _DECOR_FLAGS_PREFER_CSD_, !!state);

if(state)
{ setenv(GTK_CSD, GTK_REPLACE, 1);
}
else
{ unsetenv(GTK_CSD);
}
}
37 changes: 37 additions & 0 deletions decorations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef _WM_DECORATIONS_H_
#define _WM_DECORATIONS_H_


#include "XCB-TRL/xcb_trl.h"

typedef struct Decoration Decoration;


struct Decoration
{
/* TODO */
uint16_t w;
uint16_t h;
XCBWindow win;
XCBWindow child;
uint8_t flags;
uint8_t pad0[3];
};

/* Allocates a decoration with all properties set to 0 or NULL.
* RETURN: Decoration * on Success.
* RETURN: NULL on Failure.
*/
Decoration *X11DecorCreate(void);
/*
* NOTE: Only 1 child can be held by a decoration.
*/
void X11DecorHoldChild(Decoration *decor, XCBWindow child);
/* Maps associated decoration window.
*/
void X11DecorMap(XCBDisplay *display, Decoration *decor);

void X11DecorPreferCSD(Decoration *decor);


#endif