2008-10-02 18:47:02 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* Common declarations
|
2009-02-07 23:28:13 +00:00
|
|
|
*
|
2008-10-02 18:47:02 +00:00
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef COMMON_H
|
|
|
|
#define COMMON_H
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
#define WM_CLASS_TINT "panel"
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2016-03-22 07:25:09 +00:00
|
|
|
#include <glib.h>
|
2009-09-01 15:56:52 +00:00
|
|
|
#include <Imlib2.h>
|
2015-04-18 13:22:07 +00:00
|
|
|
#include <pango/pangocairo.h>
|
2008-10-02 18:47:02 +00:00
|
|
|
#include "area.h"
|
2017-12-19 14:28:57 +00:00
|
|
|
#include "colors.h"
|
2017-12-21 10:42:07 +00:00
|
|
|
#include "strlcat.h"
|
2015-06-21 12:50:08 +00:00
|
|
|
|
2016-03-24 19:45:17 +00:00
|
|
|
#define MAX3(a, b, c) MAX(MAX(a, b), c)
|
|
|
|
#define MIN3(a, b, c) MIN(MIN(a, b), c)
|
2016-03-22 07:25:09 +00:00
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
// mouse actions
|
2015-11-20 22:28:37 +00:00
|
|
|
typedef enum MouseAction {
|
2017-04-13 12:07:23 +00:00
|
|
|
NONE = 0,
|
|
|
|
CLOSE,
|
|
|
|
TOGGLE,
|
|
|
|
ICONIFY,
|
|
|
|
SHADE,
|
|
|
|
TOGGLE_ICONIFY,
|
|
|
|
MAXIMIZE_RESTORE,
|
|
|
|
MAXIMIZE,
|
|
|
|
RESTORE,
|
|
|
|
DESKTOP_LEFT,
|
|
|
|
DESKTOP_RIGHT,
|
|
|
|
NEXT_TASK,
|
|
|
|
PREV_TASK
|
2015-11-20 22:28:37 +00:00
|
|
|
} MouseAction;
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2016-03-24 19:45:17 +00:00
|
|
|
#define ALL_DESKTOPS 0xFFFFFFFF
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2017-08-31 16:38:31 +00:00
|
|
|
void write_string(int fd, const char *s);
|
|
|
|
void log_string(int fd, const char *s);
|
|
|
|
|
|
|
|
void dump_backtrace(int log_fd);
|
|
|
|
|
|
|
|
// sleep() returns early when signals arrive. This function does not.
|
|
|
|
void safe_sleep(int seconds);
|
|
|
|
|
|
|
|
const char *signal_name(int sig);
|
|
|
|
|
|
|
|
const char *get_home_dir();
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
// Copies a file to another path
|
|
|
|
void copy_file(const char *path_src, const char *path_dest);
|
2008-10-02 18:47:02 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
// Parses lines with the format 'key = value' into key and value.
|
|
|
|
// Strips key and value.
|
|
|
|
// Values may contain spaces and the equal sign.
|
|
|
|
// Returns 1 if both key and value could be read, zero otherwise.
|
2016-08-08 08:56:06 +00:00
|
|
|
gboolean parse_line(const char *line, char **key, char **value);
|
2009-10-25 16:36:40 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
void extract_values(const char *value, char **value1, char **value2, char **value3);
|
2016-10-02 20:56:48 +00:00
|
|
|
void extract_values_4(const char *value, char **value1, char **value2, char **value3, char **value4);
|
2009-10-25 16:36:40 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
// Executes a command in a shell.
|
2017-09-02 08:53:20 +00:00
|
|
|
pid_t tint_exec(const char *command,
|
|
|
|
const char *dir,
|
|
|
|
const char *tooltip,
|
|
|
|
Time time,
|
|
|
|
Area *area,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
gboolean terminal,
|
|
|
|
gboolean startup_notification);
|
2017-04-22 17:07:49 +00:00
|
|
|
void tint_exec_no_sn(const char *command);
|
2017-05-20 12:48:25 +00:00
|
|
|
int setenvd(const char *name, const int value);
|
2010-06-11 18:47:26 +00:00
|
|
|
|
2015-03-01 10:33:05 +00:00
|
|
|
// Returns a copy of s in which "~" is expanded to the path to the user's home directory.
|
2015-11-20 22:28:37 +00:00
|
|
|
// The caller takes ownership of the string.
|
2016-02-28 12:41:19 +00:00
|
|
|
char *expand_tilde(const char *s);
|
2015-03-01 10:33:05 +00:00
|
|
|
|
|
|
|
// The opposite of expand_tilde: replaces the path to the user's home directory with "~".
|
2015-11-20 22:28:37 +00:00
|
|
|
// The caller takes ownership of the string.
|
2016-02-28 12:41:19 +00:00
|
|
|
char *contract_tilde(const char *s);
|
2010-06-11 18:47:26 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
// Color
|
|
|
|
int hex_char_to_int(char c);
|
|
|
|
int hex_to_rgb(char *hex, int *r, int *g, int *b);
|
|
|
|
void get_color(char *hex, double *rgb);
|
2009-10-25 16:36:40 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
Imlib_Image load_image(const char *path, int cached);
|
2011-06-06 09:16:51 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
// Adjusts the alpha/saturation/brightness on an ARGB image.
|
2016-03-22 07:25:09 +00:00
|
|
|
// Parameters:
|
|
|
|
// * alpha_adjust: multiplicative:
|
|
|
|
// * 0 = full transparency
|
|
|
|
// * 1 = no adjustment
|
|
|
|
// * 2 = twice the current opacity
|
|
|
|
// * satur_adjust: additive:
|
|
|
|
// * -1 = full grayscale
|
|
|
|
// * 0 = no adjustment
|
|
|
|
// * 1 = full color
|
|
|
|
// * bright_adjust: additive:
|
|
|
|
// * -1 = black
|
|
|
|
// * 0 = no adjustment
|
|
|
|
// * 1 = white
|
|
|
|
void adjust_asb(DATA32 *data, int w, int h, float alpha_adjust, float satur_adjust, float bright_adjust);
|
2015-11-20 22:28:37 +00:00
|
|
|
Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int brightness);
|
2017-11-20 09:15:12 +00:00
|
|
|
void adjust_color(Color *color, int alpha, int saturation, int brightness);
|
2010-01-04 16:25:17 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
void create_heuristic_mask(DATA32 *data, int w, int h);
|
2015-04-18 13:22:07 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
// Renders the current Imlib image to a drawable. Wrapper around imlib_render_image_on_drawable.
|
|
|
|
void render_image(Drawable d, int x, int y);
|
2015-11-04 12:02:12 +00:00
|
|
|
|
2017-06-05 13:20:16 +00:00
|
|
|
void get_text_size2(const PangoFontDescription *font,
|
2017-04-13 12:07:23 +00:00
|
|
|
int *height_ink,
|
|
|
|
int *height,
|
|
|
|
int *width,
|
2017-06-05 13:20:16 +00:00
|
|
|
int available_height,
|
|
|
|
int available_with,
|
|
|
|
const char *text,
|
|
|
|
int text_len,
|
2017-04-13 12:07:23 +00:00
|
|
|
PangoWrapMode wrap,
|
|
|
|
PangoEllipsizeMode ellipsis,
|
|
|
|
gboolean markup);
|
2015-11-04 12:02:12 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, int font_shadow);
|
|
|
|
|
|
|
|
// Draws a rounded rectangle
|
2015-11-18 20:57:10 +00:00
|
|
|
void draw_rect(cairo_t *c, double x, double y, double w, double h, double r);
|
2016-05-17 19:59:43 +00:00
|
|
|
void draw_rect_on_sides(cairo_t *c, double x, double y, double w, double h, double r, int border_mask);
|
2015-11-18 20:57:10 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
// Clears the pixmap (with transparent color)
|
2015-11-18 20:57:10 +00:00
|
|
|
void clear_pixmap(Pixmap p, int x, int y, int w, int h);
|
|
|
|
|
2017-07-16 08:14:40 +00:00
|
|
|
void close_all_fds();
|
|
|
|
|
2016-02-28 13:53:15 +00:00
|
|
|
// Appends to the list locations all the directories contained in the environment variable var (split by ":").
|
|
|
|
// Optional suffixes are added to each directory. The suffix arguments MUST end with NULL.
|
|
|
|
// Returns the new value of the list.
|
|
|
|
GSList *load_locations_from_env(GSList *locations, const char *var, ...);
|
|
|
|
|
|
|
|
GSList *slist_remove_duplicates(GSList *list, GCompareFunc eq, GDestroyNotify fr);
|
|
|
|
|
2016-08-08 10:04:31 +00:00
|
|
|
// A trivial pointer comparator.
|
|
|
|
gint cmp_ptr(gconstpointer a, gconstpointer b);
|
|
|
|
|
2017-09-02 11:04:01 +00:00
|
|
|
GString *tint2_g_string_replace(GString *s, const char *from, const char *to);
|
|
|
|
|
2017-11-19 21:12:07 +00:00
|
|
|
void get_image_mean_color(const Imlib_Image image, Color *mean_color);
|
|
|
|
|
2016-03-24 19:45:17 +00:00
|
|
|
#define free_and_null(p) \
|
2017-04-13 12:07:23 +00:00
|
|
|
{ \
|
|
|
|
free(p); \
|
|
|
|
p = NULL; \
|
|
|
|
}
|
2015-12-05 09:05:42 +00:00
|
|
|
|
2016-03-24 19:45:17 +00:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 33, 4)
|
2015-12-27 13:29:03 +00:00
|
|
|
GList *g_list_copy_deep(GList *list, GCopyFunc func, gpointer user_data);
|
|
|
|
#endif
|
|
|
|
|
2016-03-24 19:45:17 +00:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 38, 0)
|
2015-12-27 13:29:03 +00:00
|
|
|
#define g_assert_null(expr) g_assert((expr) == NULL)
|
|
|
|
#endif
|
|
|
|
|
2017-04-22 20:21:13 +00:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 40, 0)
|
|
|
|
#define g_assert_nonnull(expr) g_assert((expr) != NULL)
|
|
|
|
#endif
|
|
|
|
|
2008-10-02 18:47:02 +00:00
|
|
|
#endif
|