summaryrefslogtreecommitdiff
path: root/src/modules/physics/e_mod_config.c
blob: ace03a953d556151b34557be35dc3737ed5f4a07 (plain) (blame)
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
#include "e.h"
#include "e_mod_main.h"
#include "e_mod_physics.h"

struct _E_Config_Dialog_Data
{
   double delay; /* delay before applying physics */
   double max_mass; /* maximum mass for a window */
   double gravity; /* gravity for a window */
   Eina_Bool ignore_fullscreen;
   Eina_Bool ignore_maximized;
   Eina_Bool ignore_shelves;
   struct
   {
      Eina_Bool disable_rotate;
      Eina_Bool disable_move;
   } shelf;
};

/* Protos */
static int _basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata);
static void        *_create_data(E_Config_Dialog *cfd);
static void         _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static int          _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);

E_Config_Dialog *
e_int_config_physics_module(E_Container *con,
                         const char *params __UNUSED__)
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;
   char buf[4096];
   Mod *mod = _physics_mod;

   if (mod->config_dialog) return NULL;
   snprintf(buf, sizeof(buf), "%s/e-module-physics.edj", e_module_dir_get(mod->module));
   v = E_NEW(E_Config_Dialog_View, 1);

   v->create_cfdata = _create_data;
   v->free_cfdata = _free_data;
   v->basic.apply_cfdata = _basic_apply_data;
   v->basic.create_widgets = _basic_create_widgets;
   v->basic.check_changed = _basic_check_changed;

   cfd = e_config_dialog_new(con, _("Physics Settings"),
                             "E", "appearance/physics", buf, 32, v, mod);
   mod->config_dialog = cfd;
   return cfd;
}

static void *
_create_data(E_Config_Dialog *cfd __UNUSED__)
{
   E_Config_Dialog_Data *cfdata;

   cfdata = E_NEW(E_Config_Dialog_Data, 1);

   cfdata->delay = _physics_mod->conf->delay;
   cfdata->max_mass = _physics_mod->conf->max_mass;
   cfdata->gravity = _physics_mod->conf->gravity;

   return cfdata;
}

static void
_free_data(E_Config_Dialog *cfd  __UNUSED__,
           E_Config_Dialog_Data *cfdata)
{
   _physics_mod->config_dialog = NULL;
   free(cfdata);
}

static int
_basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
{
#define CHECK(X) \
   if (cfdata->X != _physics_mod->conf->X) return 1

   CHECK(max_mass);
   CHECK(gravity);
   CHECK(ignore_fullscreen);
   CHECK(ignore_maximized);
   CHECK(ignore_shelves);
   CHECK(shelf.disable_move);
   CHECK(shelf.disable_rotate);
   if ((unsigned int)cfdata->delay != _physics_mod->conf->delay) return 1;

#undef CHECK
   return 0;
}

static Evas_Object *
_basic_create_widgets(E_Config_Dialog *cfd __UNUSED__,
                      Evas *evas,
                      E_Config_Dialog_Data *cfdata)
{
   Evas_Object *ob, *ol, *otb, *tab;

   tab = e_widget_table_add(evas, 0);
   evas_object_name_set(tab, "dia_table");

   otb = e_widget_toolbook_add(evas, 48 * e_scale, 48 * e_scale);

   ///////////////////////////////////////////

   ol = e_widget_list_add(evas, 0, 0);
   ob = e_widget_label_add(evas, _("Physics delay after drag"));
   e_widget_list_object_append(ol, ob, 1, 1, 0.5);
   ob = e_widget_slider_add(evas, 1, 0, _("%2.0f Frames"), 5, 20, 1, 0, &(cfdata->delay), NULL, 150);
   e_widget_list_object_append(ol, ob, 1, 1, 0.5);
   ob = e_widget_label_add(evas, _("Maximum window mass"));
   e_widget_list_object_append(ol, ob, 1, 1, 0.5);
   ob = e_widget_slider_add(evas, 1, 0, _("%2.1f kg"), 1, 6, 1, 0, &(cfdata->max_mass), NULL, 150);
   e_widget_list_object_append(ol, ob, 1, 1, 0.5);
   ob = e_widget_label_add(evas, _("Desktop gravity"));
   e_widget_list_object_append(ol, ob, 1, 1, 0.5);
   ob = e_widget_slider_add(evas, 1, 0, _("%1.1f m/s^2"), -5, 5, 1, 0, &(cfdata->gravity), NULL, 150);
   e_widget_list_object_append(ol, ob, 1, 1, 0.5);

   e_widget_toolbook_page_append(otb, NULL, _("General"), ol, 1, 1, 1, 1, 0.5, 0.5);

   ///////////////////////////////////////////

   ol = e_widget_list_add(evas, 0, 0);

   ob = e_widget_check_add(evas, _("Disable Movement"), (int*)&(cfdata->shelf.disable_move));
   e_widget_list_object_append(ol, ob, 1, 0, 0.5);

   ob = e_widget_check_add(evas, _("Disable Rotation"), (int*)&(cfdata->shelf.disable_rotate));
   e_widget_list_object_append(ol, ob, 1, 0, 0.5);

   e_widget_toolbook_page_append(otb, NULL, _("Shelves"), ol, 1, 1, 1, 1, 0.5, 0.5);

   ///////////////////////////////////////////

   ol = e_widget_list_add(evas, 0, 0);
   ob = e_widget_check_add(evas, _("Ignore Fullscreen"), (int*)&(cfdata->ignore_fullscreen));
   e_widget_list_object_append(ol, ob, 1, 0, 0.5);

   ob = e_widget_check_add(evas, _("Ignore Maximized"), (int*)&(cfdata->ignore_maximized));
   e_widget_list_object_append(ol, ob, 1, 0, 0.5);

   ob = e_widget_check_add(evas, _("Ignore Shelves"), (int*)&(cfdata->ignore_shelves));
   e_widget_list_object_append(ol, ob, 1, 0, 0.5);

   e_widget_toolbook_page_append(otb, NULL, _("Ignore"), ol, 1, 1, 1, 1, 0.5, 0.5);

   e_widget_toolbook_page_show(otb, 0);


   e_widget_table_object_append(tab, otb, 0, 0, 1, 1, 1, 1, 1, 1);
   return tab;
}


static int
_basic_apply_data(E_Config_Dialog *cfd  __UNUSED__,
                  E_Config_Dialog_Data *cfdata)
{
   if ((cfdata->delay != _physics_mod->conf->delay) ||
       (cfdata->max_mass != _physics_mod->conf->max_mass) ||
       (cfdata->ignore_fullscreen != _physics_mod->conf->ignore_fullscreen) ||
       (cfdata->ignore_maximized != _physics_mod->conf->ignore_maximized) ||
       (cfdata->gravity != _physics_mod->conf->gravity)
      )
     {
#define SET(X) _physics_mod->conf->X = cfdata->X
        _physics_mod->conf->delay = (unsigned int)cfdata->delay;
        SET(max_mass);
        SET(ignore_fullscreen);
        SET(ignore_maximized);
        SET(ignore_shelves);
        SET(gravity);
        SET(shelf.disable_move);
        SET(shelf.disable_rotate);
        e_mod_physics_shutdown();
        e_mod_physics_init();
     }
   e_config_save_queue();
   return 1;
}