aboutsummaryrefslogtreecommitdiffstats
path: root/src/mbdesktop.h
blob: 4231e589bc5f5325c85181d2ea7d27f7caf2117c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/* SPDX-License-Identifier: GPL-2.0-or-later */

#ifndef _HAVE_MBDESKTOP_H
#define _HAVE_MBDESKTOP_H

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef USE_DNOTIFY 		/* Needed for dnotify stuff from fcntl.c */
#define _GNU_SOURCE
#endif 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h> 
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <ctype.h>
#include <time.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysymdef.h>
#include <X11/keysym.h>
#include <X11/Xmd.h>

#include <zlib.h>

#include "config.h"

#include <libmb/mb.h>


#ifdef USE_XSETTINGS
#include <xsettings-client.h>
#endif 

#define DD_DIR DATADIR "/applications/" 

/* #define DD_DIR "/tmp/" */
#define PIXMAP_PATH PIXMAPSDIR


#ifdef DEBUG
#define DBG(txt, args... ) fprintf(stderr, "DT-DEBUG: " txt , ##args )
#else
#define DBG(txt, args... ) /* nothing */
#endif

#define ITEM_WIDTH  96 /* 48 */ 
#define ITEM_HEIGHT 108 /* 54 */ 
#define ICON_SIZE   64 /* 32 */

#ifdef MB_HAVE_PNG
#define NO_APP_ICON    "mbnoapp.png"
#define FOLDER_PATH    DATADIR "/pixmaps/mbfolder.png"
#else
#define NO_APP_ICON    "mbnoapp.xpm"
#define FOLDER_PATH    DATADIR "/pixmaps/mbfolder.xpm"
#endif

/* below will fall back to fixed for core X fonts */
#define FONT_DESC       "Sans bold 14px"
#define FONT_TITLE_DESC "Sans bold 14px"


#define FONT_COL "#ffffff"

#define ITEM_TEXT_ROWS 2

#define DEFAULT_DESKTOP_BG_COL "#a1b2e9"

enum {
  VIEW_ICONS,
  VIEW_LIST,
  VIEW_ICONS_ONLY,
  VIEW_TEXT_ONLY,
};

enum {
  DKTP_FONT_COL_WHITE,
  DKTP_FONT_COL_BLACK,
  DKTP_FONT_COL_SHADOW,
  DKTP_FONT_COL_UNKOWN
};

enum {	   /* from .desktop type key should this be moved to dotdesktop.c ? */
  ITEM_TYPE_UNKNOWN = 0,
  ITEM_TYPE_ROOT,

  ITEM_TYPE_DOTDESKTOP_FOLDER,
  ITEM_TYPE_DOTDESKTOP_ITEM,
  ITEM_TYPE_MODULE_ITEM,
  ITEM_TYPE_MODULE_WINDOW,
  ITEM_TYPE_APP,
  ITEM_TYPE_FOLDER,  /* Same as 'official' Directory */
  ITEM_TYPE_LINK,    /* URL  */

  ITEM_TYPE_FSDEVICE, 
  ITEM_TYPE_MIMETYPE, 
  ITEM_TYPE_DIRECTORY, 
  ITEM_TYPE_SERVICE, 
  ITEM_TYPE_SERVICETYPE ,

  ITEM_TYPE_TASK_FOLDER, 		/* Not official */
  ITEM_TYPE_PREVIOUS,
  ITEM_TYPE_CNT, 
};

enum {
  BG_SOLID = 1,
  BG_TILED_PXM,
  BG_STRETCHED_PXM,
  BG_GRADIENT_HORIZ,
  BG_GRADIENT_VERT,
  BG_CENTERED_PXM,
};

enum {
  HIGHLIGHT_OUTLINE,
  HIGHLIGHT_OUTLINE_CLEAR,
  HIGHLIGHT_FILL,
  HIGHLIGHT_FILL_CLEAR,
};

typedef void (*MBDesktopCB)( void *data1, void *data2 ) ;

typedef struct _mbdesktop_item {

  int                     type;
  int                     subtype; /* user defined type */
  int                     view;

  char                   *name;
  char                   *name_extended;
  char                   *comment;
  char                   *icon_name;
  MBPixbufImage          *icon;
  void                   *data;

  Window                  win;

  MBDesktopCB             activate_cb;
  MBDesktopCB             populate_cb; 	/* only populates children */

  struct _mbdesktop_item *item_next_sibling; 
  struct _mbdesktop_item *item_prev_sibling; 
  struct _mbdesktop_item *item_child; 
  struct _mbdesktop_item *item_parent; 

  /* Used for folders to remember there scroll pos when backed up to */
  struct _mbdesktop_item *saved_scroll_offset_item; 

  int                     x;
  int                     y;
  int                     width;
  int                     height;

  struct MBDesktopFolderModule *module_handle; /* XXX to go */

} MBDesktopItem;

typedef struct MBDesktopModuleslist
{
  struct MBDesktopFolderModule *module_handle;
  void *dl_handle;
  struct MBDesktopModuleslist *next;

} MBDesktopModuleslist;

typedef struct mbtest {
  char *data1;
  char *data2;
} MBTest;

typedef struct item_sizes {

  int width;
  int height;
  int icon_size;
  int box_yoffset;
  int box_size;
  int txt_yoffset;

} MBDesktopItemDimentions;

typedef struct _mbdesktop_bg {
  int type;

  union {
    char *filename;
    int cols[3];
    int gcols[6];
  } data;

} MBDesktopBG;

typedef struct _mbdesktop {

  Display *dpy;
  int scr;

  MBFont  *font;
  MBFont  *titlefont;

  MBColor *fgcol;
  MBColor *bgcol;

  MBDrawable *backing_cache;

  GC invert_gc;
  GC gc;

  Window root, win_top_level;

  Bool have_focus;
  Bool user_overide_font_col;
  Bool user_overide_font_outline;

  int                     current_view; 		
  MBDesktopItemDimentions itemDim;

  MBDotDesktopFolders     *ddfolders;

  MBDesktopItem           *top_head_item;      /* Very top of item list  */
  MBDesktopItem           *current_head_item;  /* Top of each child list */
  MBDesktopItem           *kbd_focus_item;     /* Kdb focused item       */
  MBDesktopItem           *scroll_offset_item; /* Initially displayed item if 
						  scrolled */
  MBDesktopItem           *last_visible_item; 
  MBDesktopItem           *current_folder_item; /* The current opened folder */

  Bool                     had_kbd_input;

  int                      current_view_columns;
  int                      current_view_rows;

  int desktop_width;
  int desktop_height;
  int workarea_width;
  int workarea_height;
  int workarea_x;
  int workarea_y;

  MBPixbuf               *pixbuf;   /* MBPixbuf ref  */

  Pixmap                  root_pxm;

  MBPixbufImage *img_scroll_up;
  MBPixbufImage *img_scroll_down;
  Bool           scroll_active;

  MBPixbufImage *bg_img;
  MBDesktopBG *bg;

  char *theme_name;
  char *bg_def;

  Bool view_type;

  int icon_size;  
  int icon_padding;
  int item_width;
  int item_height;
  int title_offset;

  Bool                    use_title_header;
  Bool                    use_text_outline;

  Window                  win_plugin;
  XRectangle              win_plugin_rect;

#ifdef USE_FAM

  FAMConnection fam_conn;
  FAMRequest *fam_req;

#endif 


#ifdef USE_XSETTINGS
  XSettingsClient *xsettings_client;
  Bool             xsettings_have_bg;
  Bool             xsettings_have_manager;
#endif 

  Atom window_type_atom, window_type_desktop_atom, desktop_manager_atom,
    window_type_dialog_atom, window_state_atom, window_state_modal_atom,
    window_utf8_name_atom, utf8_atom, atom_mb_theme;

  char *top_level_name;

  int    type_register_cnt;

  MBDesktopModuleslist *modules;

  MBColor *hl_col;
  int    font_col_type;

  /* Progress Dialog stuff  */
  Window win_dialog;
  Pixmap win_dialog_backing;
  int    win_dialog_w;
  int    win_dialog_h;


  /* TOGO */
  time_t dd_dir_mtime;
  char *dd_dir;
  char *pixmaps_dir;
  char *folder_img_path;

} MBDesktop;


struct moddentry
{
  struct MBDesktopFolderModule *handle;
  struct moddentry             *next;
};

/* Module structs  should go in mbdesktop_module.h */

typedef struct MBDesktopModuleInfo 
{
  char *name;
  char *desc;
  char *author;
  int   major;
  int   minor;
  int   micro;
  int   api;

} MBDesktopModuleInfo;

typedef struct MBDesktopFolderModule
{

  MBDesktopModuleInfo *mod_info;
  int            (*mod_init)   (MBDesktop                    *mb, 
				struct MBDesktopFolderModule *folder_module,
				char                         *arg_str);
  void           (*mod_xevent) (MBDesktop                    *mb, 
				struct MBDesktopFolderModule *folder_module,
				XEvent                       *xevent);
  void            *user_data;
} MBDesktopFolderModule;


void
mbdesktop_calculate_item_dimentions(MBDesktop *mb);


/* ------------------- */


Display *
mbdesktop_xdisplay (MBDesktop *mb);

Window
mbdesktop_xrootwin (MBDesktop *mb);

MBPixbuf *
mbdesktop_mbpixbuf (MBDesktop *mb);

int
mbdesktop_xscreen (MBDesktop *mb);

int
mbdesktop_icon_size (MBDesktop *mb);

void
mbdesktop_set_font(MBDesktop *mb, char *spec);

void
mbdesktop_set_title_font(MBDesktop *mb, char *spec);

void
mbdesktop_set_font_color(MBDesktop *mb, char *spec);

void
mbdesktop_switch_icon_theme (MBDesktop     *mb, 
			     MBDesktopItem *item );

void
mbdesktop_switch_theme (MBDesktop *mb, char *theme_name );

void
mbdesktop_set_scroll_buttons(MBDesktop *mb);

int
mbdesktop_current_folder_view ( MBDesktop *mb );

void 
mbdesktop_view_paint(MBDesktop *mb, Bool use_cache);

Bool
mbdesktop_get_workarea(MBDesktop *mb, int *x, int *y, int *w, int *h);

void
mbdesktop_items_free(MBDesktop *mb, MBDesktopItem *item);

Bool
mbdesktop_bg_parse_spec(MBDesktop *mb, char *spec);

void
mbdesktop_progress_dialog_init (MBDesktop   *mb);

void
mbdesktop_progress_dialog_set_percentage (MBDesktop   *mb, 
					  int          percentage);

void
mbdesktop_progress_dialog_open (MBDesktop   *mb);

void
mbdesktop_progress_dialog_close (MBDesktop   *mb);


#endif