yabar/include/yabar.h

354 lines
7.8 KiB
C
Raw Normal View History

2016-03-14 13:52:48 +02:00
/*
* Yabar - A modern and lightweight status bar for X window managers.
*
* Copyright (c) 2016, George Badawi
* See LICENSE for more information.
*
*/
2016-03-18 14:42:01 +02:00
#ifndef YABAR_H
#define YABAR_H
2016-03-14 13:52:48 +02:00
#include <stdio.h>
#include <errno.h>
2016-03-17 08:58:30 +02:00
#define __USE_XOPEN2K //for setenv implicit function decleration warning
2016-03-14 13:52:48 +02:00
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <ctype.h>
#include <xcb/xcb.h>
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <cairo/cairo-xcb.h>
#include <cairo/cairo.h>
#include <signal.h>
#include <getopt.h>
#include <libconfig.h>
2016-03-17 20:07:42 +02:00
#include <xcb/randr.h>
#include <xcb/xcb_ewmh.h>
2016-03-17 20:07:42 +02:00
2016-04-12 16:23:12 +02:00
#include <gdk-pixbuf/gdk-pixbuf.h>
//just to suppress gcc syntastic warnings in vim
//VERSION is obtained from Makefile
2016-03-15 11:22:46 +02:00
#ifndef VERSION
#define VERSION ""
#endif
2016-03-17 08:58:30 +02:00
2016-03-23 08:41:09 +02:00
extern char *strdup(const char *s); //to suppress implicit decleration warning for strdup
2016-03-18 14:42:01 +02:00
#define BUFSIZE_EXT 512 //buffer size for external blocks
#define BUFSIZE_EXT_PANGO 1024 //buffer size for extern blocks with pango markup
#define BUFSIZE_INT 256 //initial value of buffer size for internal blocks, can be overridden in runtime if needed
2016-03-14 13:52:48 +02:00
#define CFILELEN 256
#define YA_DEF_FONT "sans bold 9"
#define PT1 printf("%d:%s:%s\n", __LINE__, __FUNCTION__, __FILE__)
2016-03-15 11:43:06 +02:00
#define GET_ALPHA(c) ((double)(((c)>>24) & 0xff)/255.0)
#define GET_RED(c) ((double)(((c)>>16) & 0xff)/255.0)
#define GET_GREEN(c) ((double)(((c)) & 0xff)/255.0)
#define GET_BLUE(c) ((double)(((c)>>8) & 0xff)/255.0)
2016-03-14 13:52:48 +02:00
2016-04-24 07:45:44 +02:00
#define GET_MIN(A, B) ((A) < (B) ? (A) : (B))
#define GET_MAX(A, B) ((A) > (B) ? (A) : (B))
#define DRAW_TEXT(blk) if((blk->attr & BLKA_VAR_WIDTH)) \
ya_draw_text_var_width(blk);\
else \
ya_draw_pango_text(blk);
2016-03-14 13:52:48 +02:00
enum {
A_LEFT =0,
A_CENTER=1,
A_RIGHT=2
};
enum {
YA_TOP = 0,
YA_BOTTOM,
YA_LEFT,
YA_RIGHT
};
//Flags of block attributes; stored in blk->attr
2016-03-14 13:52:48 +02:00
enum {
BLKA_PERIODIC = 1<<0,
BLKA_PERSIST = 1<<1,
BLKA_ONCE = 1<<2,
BLKA_INTERNAL = 1<<3,
BLKA_EXTERNAL = 1<<4,
2016-03-14 13:52:48 +02:00
BLKA_MARKUP_PANGO = 1<<5,
BLKA_FIXED_WIDTH = 1<<6,
BLKA_ALIGN_LEFT = 1<<7,
BLKA_ALIGN_CENTER = 1<<8,
BLKA_ALIGN_RIGHT = 1<<9,
BLKA_BGCOLOR = 1<<10,
BLKA_FGCOLOR = 1<<11,
2016-03-14 13:52:48 +02:00
BLKA_UNDERLINE = 1<<12,
2016-03-23 20:06:48 +02:00
BLKA_OVERLINE = 1<<13,
BLKA_INHERIT = 1<<14,
2016-04-12 16:23:12 +02:00
BLKA_INTERN_X_EV = 1<<15,
BLKA_ICON = 1<<16,
2016-04-24 07:45:44 +02:00
BLKA_DIRTY_COL = 1<<17,
BLKA_VAR_WIDTH = 1<<18
2016-03-14 13:52:48 +02:00
};
2016-03-23 20:06:48 +02:00
2016-04-25 09:53:26 +02:00
// Flags of bar attributes; stored in bar->attr
2016-03-23 20:06:48 +02:00
enum {
2016-03-27 18:23:13 +02:00
BARA_INHERIT = 1<<0,
BARA_INHERIT_ALL = 1<<1,
2016-04-24 07:45:44 +02:00
BARA_DYN_COL = 1<<2,
BARA_REDRAW = 1<<3
2016-03-23 20:06:48 +02:00
};
2016-04-25 09:53:26 +02:00
//for variable-width blocks, check for whether the bar should be redrawn.
2016-04-24 07:45:44 +02:00
#define SHOULD_REDRAW(blk) (((blk)->attr & BLKA_VAR_WIDTH) && (!((blk)->bar->attr & BARA_REDRAW)) && ((blk)->curwidth != (blk)->width))
#ifdef YA_INTERNAL_EWMH
2016-07-07 10:18:50 +09:00
#define YA_INTERNAL_LEN 13
#else
2016-07-07 10:18:50 +09:00
#define YA_INTERNAL_LEN 11
#endif
enum {
YA_INT_DATE = 0,
YA_INT_UPTIME,
YA_INT_THERMAL,
YA_INT_BRIGHTNESS,
YA_INT_BANDWIDTH,
YA_INT_MEMORY,
YA_INT_CPU,
2016-07-07 10:18:50 +09:00
YA_INT_LOADAVG,
YA_INT_DISKIO,
YA_INT_NETWORK,
2016-04-14 16:22:02 -07:00
YA_INT_BATTERY,
YA_INT_TITLE,
YA_INT_WORKSPACE
};
2016-04-04 22:57:05 +02:00
2016-03-23 20:06:48 +02:00
#define NOT_INHERIT_BAR(bar) (((bar)->attr & BARA_INHERIT)==0)
2016-03-24 19:40:31 +02:00
#define NOT_INHERIT_BLK(blk) (((blk)->attr & BLKA_INHERIT)==0)
2016-03-23 20:06:48 +02:00
2016-03-18 14:42:01 +02:00
#define CMONLEN 16
typedef struct ya_monitor ya_monitor_t;
typedef struct ya_bar ya_bar_t;
typedef struct ya_block ya_block_t;
typedef struct blk_intern blk_intern_t;
typedef struct blk_img blk_img_t;
typedef struct intern_ewmh_blk ya_ewmh_blk;
typedef void(*funcp)(ya_block_t *);
struct reserved_blk {
char *name;
funcp function;
};
2016-04-25 09:53:26 +02:00
//Instead of searching for block that has BLKA_INTERN_X_EV enabled in all bars and all their blocks,
//this struct is introduced to add such blocks in a small linked list in order to quickly
//handle when an event occurs.
struct intern_ewmh_blk {
ya_block_t * blk;
struct intern_ewmh_blk *prev_ewblk;
struct intern_ewmh_blk *next_ewblk;
};
2016-03-18 14:42:01 +02:00
struct ya_monitor {
char name[CMONLEN];
xcb_rectangle_t pos;
struct ya_monitor *prev_mon;
struct ya_monitor *next_mon;
};
2016-03-14 13:52:48 +02:00
struct ya_block {
2016-03-23 20:06:48 +02:00
char *name;
char *buf;
size_t bufsize;
2016-03-14 13:52:48 +02:00
char *cmd;
char *button_cmd[5];
2016-03-14 13:52:48 +02:00
uint32_t sleep;
uint32_t attr; //block atributes
2016-03-14 13:52:48 +02:00
uint8_t align;
uint8_t justify; //justify text within block
2016-03-24 15:29:54 +02:00
uint16_t shift;
2016-03-14 13:52:48 +02:00
uint16_t width;
xcb_pixmap_t pixmap;
xcb_gcontext_t gc;
struct ya_block *prev_blk;
struct ya_block *next_blk;
ya_bar_t *bar;
pthread_t thread;
pid_t pid;
2016-03-14 13:52:48 +02:00
uint32_t bgcolor; //background color
uint32_t fgcolor; //foreground color
uint32_t ulcolor; //underline color
uint32_t olcolor; //overline color
blk_intern_t *internal;
2016-04-04 22:57:05 +02:00
#ifdef YA_DYN_COL
char *strbuf;
uint32_t bgcolor_old; //initial background color
uint32_t fgcolor_old; //initial foreground color
uint32_t ulcolor_old; //initial underline color
uint32_t olcolor_old; //initial overline color
#endif
2016-04-12 16:23:12 +02:00
#ifdef YA_ICON
blk_img_t *img;
2016-04-12 16:23:12 +02:00
#endif //YA_ICON
2016-04-24 07:45:44 +02:00
#ifdef YA_MUTEX
pthread_mutex_t mutex;
#endif //YA_MUTEX
2016-04-25 09:53:26 +02:00
#ifdef YA_VAR_WIDTH
2016-04-24 07:45:44 +02:00
int curwidth;
2016-04-25 09:53:26 +02:00
#endif //YA_VAR_WIDTH
};
2016-04-25 09:53:26 +02:00
//Internal block data struct
struct blk_intern {
char *prefix;
char *suffix;
char *option[3];
uint8_t index;
bool spacing;
2016-03-14 13:52:48 +02:00
};
2016-04-25 09:53:26 +02:00
//Icon data struct
struct blk_img {
char path[CFILELEN];
uint16_t x;
uint16_t y;
double scale_w;
double scale_h;
};
2016-03-14 13:52:48 +02:00
struct ya_bar {
2016-03-23 20:06:48 +02:00
char *name;
char *button_cmd[5];
uint16_t occupied_width[3]; // occupied for each alignment (left, center and right)
2016-03-14 13:52:48 +02:00
uint16_t hgap; //horizontal gap
uint16_t vgap; //vertical gap
2016-03-14 13:52:48 +02:00
uint32_t bgcolor; //background color
2016-03-14 13:52:48 +02:00
uint16_t width;
uint16_t height;
xcb_window_t win;
uint8_t position; //top, bottom, left or right.
2016-03-14 13:52:48 +02:00
PangoFontDescription *desc;
ya_block_t *curblk[3];
/* curblk[i] should point to the last added block for each alignment. then
* should point to the first block for each alignment after invoking ya_execute()
*/
2016-03-14 13:52:48 +02:00
ya_bar_t *prev_bar;
ya_bar_t *next_bar;
uint8_t ulsize; //underline size
uint8_t olsize; //overline size
uint8_t slack; //slack size
2016-03-18 14:42:01 +02:00
uint32_t brcolor; //border color
uint8_t brsize; //border size
uint8_t attr; //bar attributes
2016-03-21 15:36:32 +02:00
2016-03-18 14:42:01 +02:00
ya_monitor_t *mon;
2016-04-24 07:45:44 +02:00
#ifdef YA_MUTEX
pthread_mutex_t mutex;
#endif //YA_MUTEX
2016-04-25 09:53:26 +02:00
#ifdef YA_NOWIN_COL
xcb_gcontext_t gc;
uint32_t bgcolor_none;
#endif //YA_NOWIN_COL
2016-03-14 13:52:48 +02:00
};
2016-04-25 09:53:26 +02:00
//Falgs of gen_flag in yabar_gen_info struct
2016-03-14 13:52:48 +02:00
enum {
2016-03-17 20:07:42 +02:00
GEN_EXT_CONF = 1 << 0,
GEN_RANDR = 1 << 1,
GEN_EWMH = 1 << 2
2016-03-17 20:07:42 +02:00
};
2016-03-14 13:52:48 +02:00
struct yabar_gen_info {
xcb_connection_t *c;
xcb_screen_t *scr;
xcb_visualtype_t *visualtype;
xcb_colormap_t colormap;
uint16_t barnum;
ya_bar_t *curbar;
uint8_t depth;
uint8_t gen_flag;
2016-03-17 20:07:42 +02:00
ya_monitor_t *curmon;
#ifdef YA_INTERNAL_EWMH
xcb_ewmh_connection_t *ewmh;
2016-04-25 09:53:26 +02:00
xcb_window_t curwin; //current window
xcb_window_t lstwin; //last window
uint32_t curws;
uint32_t lstws;
ya_ewmh_blk *ewmh_blk;
#endif //YA_INTERNAL_EWMH
2016-03-14 13:52:48 +02:00
};
typedef struct yabar_gen_info yabar_info_t;
2016-03-14 13:52:48 +02:00
extern yabar_info_t ya;
extern char conf_file[CFILELEN];
extern struct reserved_blk ya_reserved_blks[YA_INTERNAL_LEN];
2016-03-23 09:13:58 +02:00
2016-03-14 13:52:48 +02:00
void ya_init();
void ya_execute();
2016-03-23 09:13:58 +02:00
void ya_process_opt(int argc, char *argv[]);
xcb_visualtype_t * ya_get_visualtype();
void ya_config_parse();
void ya_create_bar(ya_bar_t * bar);
void ya_create_block(ya_block_t *blk);
2016-04-04 22:57:05 +02:00
void ya_buf_color_parse(ya_block_t *blk);
2016-03-23 09:13:58 +02:00
void ya_draw_pango_text(struct ya_block *blk);
2016-05-09 16:19:50 +02:00
//void ya_exec_button(ya_block_t * blk, xcb_button_press_event_t *eb);
2016-03-23 09:13:58 +02:00
2016-03-14 13:52:48 +02:00
ya_block_t * ya_get_blk_from_event( xcb_button_press_event_t *eb);
2016-03-23 09:13:58 +02:00
void ya_get_cur_window_title(ya_block_t * blk);
void ya_handle_button( xcb_button_press_event_t *eb);
void ya_handle_prop_notify(xcb_property_notify_event_t *ep);
2016-04-12 16:23:12 +02:00
cairo_surface_t * ya_draw_graphics(ya_block_t *blk);
void ya_redraw_bar(ya_bar_t *bar);
2016-04-24 07:45:44 +02:00
void ya_resetup_bar(ya_block_t *blk);
void ya_draw_text_var_width(ya_block_t * blk);
2016-05-09 18:22:21 +02:00
//void ya_get_text_max_width(ya_block_t *blk);
//void ya_draw_bar_var(ya_block_t *blk);
void ya_inherit_bar_bgcol(ya_block_t *blk);
void ya_draw_bar_curwin(ya_bar_t *bar);
2016-03-18 14:42:01 +02:00
#endif /*YABAR_H*/