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>
|
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>
|
|
|
|
|
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
|
|
|
|
2016-03-14 13:52:48 +02:00
|
|
|
#define BUFSIZE 512
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
A_LEFT =0,
|
|
|
|
A_CENTER=1,
|
|
|
|
A_RIGHT=2
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
YA_TOP = 0,
|
|
|
|
YA_BOTTOM,
|
|
|
|
YA_LEFT,
|
|
|
|
YA_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BLKA_PERIODIC = 1<<0,
|
|
|
|
BLKA_PERSIST = 1<<1,
|
|
|
|
BLKA_ONCE = 1<<2,
|
|
|
|
BLKA_INTERNAL = 1<<3,
|
|
|
|
BLKA_EXTERNAL = 1<<4,
|
|
|
|
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,
|
|
|
|
BLKA_UNDERLINE = 1<<12,
|
2016-03-23 20:06:48 +02:00
|
|
|
BLKA_OVERLINE = 1<<13,
|
|
|
|
BLKA_INHERIT = 1<<14
|
2016-03-14 13:52:48 +02:00
|
|
|
};
|
|
|
|
|
2016-03-23 20:06:48 +02:00
|
|
|
|
|
|
|
enum {
|
|
|
|
BARA_INHERIT = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NOT_INHERIT_BAR(bar) (((bar)->attr & BARA_INHERIT)==0)
|
2016-03-24 15:29:54 +02:00
|
|
|
#define NOT_INHERIT_BLK(nlk) (((blk)->attr & BLKA_INHERIT)==0)
|
2016-03-23 20:06:48 +02:00
|
|
|
|
2016-03-24 11:37:27 +02:00
|
|
|
//#ifdef YABAR_RANDR
|
2016-03-18 14:42:01 +02:00
|
|
|
|
|
|
|
#define CMONLEN 16
|
|
|
|
|
|
|
|
typedef struct ya_monitor ya_monitor_t;
|
|
|
|
struct ya_monitor {
|
|
|
|
char name[CMONLEN];
|
|
|
|
xcb_rectangle_t pos;
|
|
|
|
struct ya_monitor *prev_mon;
|
|
|
|
struct ya_monitor *next_mon;
|
|
|
|
};
|
2016-03-24 11:37:27 +02:00
|
|
|
//#endif // YABAR_RANDR
|
2016-03-18 14:42:01 +02:00
|
|
|
|
2016-03-14 13:52:48 +02:00
|
|
|
typedef struct ya_bar ya_bar_t;
|
|
|
|
struct ya_block {
|
2016-03-23 20:06:48 +02:00
|
|
|
char *name;
|
2016-03-14 13:52:48 +02:00
|
|
|
char buf [BUFSIZE];
|
|
|
|
char *cmd;
|
|
|
|
char *button_cmd[5];
|
|
|
|
|
|
|
|
uint32_t sleep;
|
2016-03-24 15:29:54 +02:00
|
|
|
uint32_t attr;
|
2016-03-14 13:52:48 +02:00
|
|
|
uint8_t align;
|
2016-03-23 10:57:09 +02:00
|
|
|
uint8_t justify;
|
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;
|
2016-03-22 07:46:28 +02:00
|
|
|
pid_t pid;
|
2016-03-14 13:52:48 +02:00
|
|
|
|
|
|
|
uint32_t bgcolor;
|
|
|
|
uint32_t fgcolor;
|
|
|
|
uint32_t ulcolor;
|
|
|
|
uint32_t olcolor;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct ya_block ya_block_t;
|
|
|
|
|
|
|
|
struct ya_bar {
|
2016-03-23 20:06:48 +02:00
|
|
|
char *name;
|
2016-03-14 13:52:48 +02:00
|
|
|
uint16_t occupied_width[3];
|
|
|
|
|
|
|
|
uint16_t hgap;
|
|
|
|
uint16_t vgap;
|
|
|
|
|
|
|
|
uint32_t bgcolor;
|
|
|
|
uint16_t width;
|
|
|
|
uint16_t height;
|
|
|
|
|
|
|
|
xcb_window_t win;
|
|
|
|
uint8_t position;
|
|
|
|
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
|
|
|
|
ya_block_t *curblk[3];
|
|
|
|
|
|
|
|
ya_bar_t *prev_bar;
|
|
|
|
ya_bar_t *next_bar;
|
|
|
|
|
|
|
|
uint8_t ulsize;
|
|
|
|
uint8_t olsize;
|
|
|
|
uint8_t slack;
|
2016-03-18 14:42:01 +02:00
|
|
|
|
2016-03-21 15:36:32 +02:00
|
|
|
uint32_t brcolor;
|
|
|
|
uint8_t brsize;
|
2016-03-23 20:06:48 +02:00
|
|
|
uint8_t attr;
|
2016-03-21 15:36:32 +02:00
|
|
|
|
2016-03-24 11:37:27 +02:00
|
|
|
//#ifdef YABAR_RANDR
|
2016-03-18 14:42:01 +02:00
|
|
|
ya_monitor_t *mon;
|
2016-03-24 11:37:27 +02:00
|
|
|
//#endif //YABAR_RANDR
|
2016-03-14 13:52:48 +02:00
|
|
|
};
|
|
|
|
|
2016-03-17 08:58:30 +02:00
|
|
|
//typedef struct ya_bar ya_bar_t;
|
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
|
|
|
|
};
|
|
|
|
|
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-24 11:37:27 +02:00
|
|
|
//#ifdef YABAR_RANDR
|
2016-03-17 20:07:42 +02:00
|
|
|
ya_monitor_t *curmon;
|
2016-03-24 11:37:27 +02:00
|
|
|
//#endif //YABAR_RANDR
|
2016-03-14 13:52:48 +02:00
|
|
|
};
|
|
|
|
typedef struct yabar_gen_info yabar_info_t;
|
|
|
|
|
|
|
|
extern yabar_info_t ya;
|
|
|
|
extern char conf_file[CFILELEN];
|
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);
|
|
|
|
|
|
|
|
void ya_draw_pango_text(struct ya_block *blk);
|
2016-03-24 11:37:27 +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
|
|
|
|
2016-03-18 14:42:01 +02:00
|
|
|
#endif /*YABAR_H*/
|