Subversion Repositories Kolibri OS

Rev

Rev 9453 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9453 Rev 9597
1
#define MEMSIZE 1024*80
1
#define MEMSIZE 1024*80
2
 
2
 
3
//===================================================//
3
//===================================================//
4
//                                                   //
4
//                                                   //
5
//                       LIB                         //
5
//                       LIB                         //
6
//                                                   //
6
//                                                   //
7
//===================================================//
7
//===================================================//
8
 
8
 
9
#include "../lib/gui.h"
9
#include "../lib/gui.h"
10
#include "../lib/list_box.h"
10
#include "../lib/list_box.h"
11
#include "../lib/collection.h"
11
#include "../lib/collection.h"
12
#include "../lib/patterns/restart_process.h"
12
#include "../lib/patterns/restart_process.h"
13
 
13
 
14
#include "../lib/mem.h" 
14
#include "../lib/mem.h" 
15
 
15
 
16
#include "../lib/obj/libini.h"
16
#include "../lib/obj/libini.h"
17
 
17
 
18
//===================================================//
18
//===================================================//
19
//                                                   //
19
//                                                   //
20
//                       DATA                        //
20
//                       DATA                        //
21
//                                                   //
21
//                                                   //
22
//===================================================//
22
//===================================================//
23
 
23
 
24
int current_process_id = 0;
24
int current_process_id = 0;
25
int proc_list[256];
25
int proc_list[256];
26
collection attached=0;
26
collection attached=0;
27
 
27
 
28
llist list;
28
llist list;
29
 
29
 
30
_ini ini = { "/sys/settings/appicons.ini", "icons"};
30
_ini ini = { "/sys/settings/appicons.ini", "icons"};
31
 
31
 
32
proc_info Form;
32
proc_info Form;
33
proc_info Process;
33
proc_info Process;
34
 
34
 
35
enum {
35
enum {
36
	ATTACHEMENT_BOTTOM,
36
	ATTACHEMENT_BOTTOM,
37
	ATTACHEMENT_LEFT,
37
	ATTACHEMENT_LEFT,
38
	ATTACHEMENT_TOP,
38
	ATTACHEMENT_TOP,
39
	ATTACHEMENT_RIGHT
39
	ATTACHEMENT_RIGHT
40
};
40
};
41
int attachement = ATTACHEMENT_BOTTOM;
41
int attachement = ATTACHEMENT_BOTTOM;
42
 
42
 
43
#define CELLW 40
43
#define CELLW 40
44
#define CELLH 40
44
#define CELLH 40
45
 
45
 
46
dword COLOR_BG      = 0x3B3B3B;
46
dword COLOR_BG      = 0x3B3B3B;
47
dword COLOR_MENU_BG = 0x323232;
47
dword COLOR_MENU_BG = 0x323232;
48
dword COLOR_OPENED  = 0x999999;
48
dword COLOR_OPENED  = 0x999999;
49
dword COLOR_ACTIVE  = 0x0099FF;
49
dword COLOR_ACTIVE  = 0x0099FF;
50
dword COLOR_TEXT    = 0xFFFfff;
50
dword COLOR_TEXT    = 0xFFFfff;
51
 
51
 
52
 
52
 
53
//===================================================//
53
//===================================================//
54
//                                                   //
54
//                                                   //
55
//                       CODE                        //
55
//                       CODE                        //
56
//                                                   //
56
//                                                   //
57
//===================================================//
57
//===================================================//
58
 
58
 
59
void main()
59
void main()
60
{
60
{
61
	int btn;
61
	int btn;
62
	load_dll(libini, #lib_init,1);
62
	load_dll(libini, #lib_init,1);
63
 
63
 
64
	ini_get_int stdcall ("/sys/appicons.ini", "taskbar", "attachement", ATTACHEMENT_BOTTOM); 
64
	ini_get_int stdcall ("/sys/appicons.ini", "taskbar", "attachement", ATTACHEMENT_BOTTOM); 
65
	attachement = EAX;
65
	attachement = EAX;
66
 
66
 
67
	SetAttachement();
67
	SetAttachement();
68
	GetAttachedItems();
68
	GetAttachedItems();
69
	
69
	
70
	GetProcessInfo(#Form, SelfInfo);
70
	GetProcessInfo(#Form, SelfInfo);
71
	SetWindowLayerBehaviour(-1, ZPOS_DESKTOP);
71
	SetWindowLayerBehaviour(-1, ZPOS_DESKTOP);
72
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
72
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
73
	loop() switch(@WaitEventTimeout(50))
73
	loop() switch(@WaitEventTimeout(50))
74
	{
74
	{
75
	   	case evMouse:
75
	   	case evMouse:
76
			if (!CheckActiveProcess(Form.ID)) break;
76
			if (!CheckActiveProcess(Form.ID)) break;
77
			mouse.get();
77
			mouse.get();
78
			if (mouse.down) {}
78
			if (mouse.down) {}
79
			//if (list.ProcessMouse()) DrawProcessList();
79
			//if (list.ProcessMouse()) DrawProcessList();
80
			break;
80
			break;
81
		case evKey:
81
		case evKey:
82
			GetKeys();
82
			GetKeys();
83
			if (key_scancode == SCAN_CODE_ESC) {
83
			if (key_scancode == SCAN_CODE_ESC) {
84
				RunProgram(#program_path, NULL);
84
				RunProgram(#program_path, NULL);
85
				ExitProcess();
85
				ExitProcess();
86
			}
86
			}
87
			break;
87
			break;
88
		case evButton:
88
		case evButton:
89
			btn = @GetButtonID();
89
			btn = @GetButtonID();
90
			btn -= 100;
90
			btn -= 100;
91
			if (btn < attached.count) RunProgram(attached.get(btn), NULL);
91
			if (btn < attached.count) RunProgram(attached.get(btn), NULL);
92
			else EventSetActiveProcess(btn);
92
			else EventSetActiveProcess(btn);
93
			break;
93
			break;
94
		case evReDraw:
94
		case evReDraw:
95
			DefineUnDragableWindow(NULL, NULL, NULL, NULL);
95
			DefineUnDragableWindow(NULL, NULL, NULL, NULL);
96
			list.SetSizes(0, 0, Form.width+1, Form.height+2, CELLH);
96
			list.SetSizes(0, 0, Form.width+1, Form.height+2, CELLH);
97
		default:
97
		default:
98
			DrawProcessList();
98
			DrawProcessList();
99
	}
99
	}
100
}
100
}
101
 
101
 
102
 
102
 
103
void GetProcessList()
103
void GetProcessList()
104
{
104
{
105
	int i, j;
105
	int i, j;
106
	list.count=0;
106
	list.count=0;
107
 
107
 
108
	for (i=0; i
108
	for (i=0; i
109
	{
109
	{
110
		proc_list[list.count] = 0;
110
		proc_list[list.count] = 0;
111
		list.count++;
111
		list.count++;
112
	}
112
	}
113
 
113
 
114
	for (i=0; i
114
	for (i=0; i
115
	{
115
	{
116
		GetProcessInfo(#Process, i);
116
		GetProcessInfo(#Process, i);
117
		if (Process.name) 
117
		if (Process.name) 
118
		{
118
		{
119
			for (j=0; j<11; j++) if (Process.name[j]!=' ') { 				
119
			for (j=0; j<11; j++) if (Process.name[j]!=' ') { 				
120
				//do not show system process
120
				//do not show system process
121
				if (Process.name[0]=='@') break;
121
				if (Process.name[0]=='@') break;
122
				if (!strcmp(#Process.name, "IDLE")) break;
122
				if (!strcmp(#Process.name, "IDLE")) break;
123
				if (!strcmp(#Process.name, "OS")) break;
123
				if (!strcmp(#Process.name, "OS")) break;
124
				if (!Process.width) && (!Process.height) break;
124
				if (!Process.width) && (!Process.height) break;
125
				proc_list[list.count] = i;
125
				proc_list[list.count] = i;
126
				list.count++;
126
				list.count++;
127
				break; 
127
				break; 
128
			}
128
			}
129
		}
129
		}
130
	}
130
	}
131
}
131
}
132
 
132
 
133
void DrawProcessList()
133
void DrawProcessList()
134
{
134
{
135
	#define ACTIVE_SIZE 3
135
	#define ACTIVE_SIZE 3
136
	#define CELL_MARGIN_X 10
136
	#define CELL_MARGIN_X 10
137
	#define CELL_MARGIN_Y 4
137
	#define CELL_MARGIN_Y 4
138
	#define CELL_PADDING 4
138
	#define CELL_PADDING 4
139
	int i;
139
	int i;
140
	int posy=list.y;
140
	int posy=list.y;
141
	int posx=list.x;
141
	int posx=list.x;
142
	int icon_n;
142
	int icon_n;
143
	dword status_color;
143
	dword status_color;
144
 
144
 
145
	GetProcessList();
145
	GetProcessList();
146
 
146
 
147
	for (i=0; i
147
	for (i=0; i
148
	{
148
	{
149
		if (proc_list[i+list.first]==0) {
149
		if (proc_list[i+list.first]==0) {
150
			status_color = COLOR_BG;
150
			status_color = COLOR_BG;
151
			icon_n = ini.GetInt(attached.get(i+list.first)+strrchr(attached.get(i+list.first),'/'), 2);
151
			icon_n = ini.GetInt(attached.get(i+list.first)+strrchr(attached.get(i+list.first),'/'), 2);
152
		} 
152
		} 
153
		else {
153
		else {
154
			GetProcessInfo(#Process, proc_list[i+list.first]);
154
			GetProcessInfo(#Process, proc_list[i+list.first]);
155
			strlwr(#Process.name);
155
			strlwr(#Process.name);
156
			icon_n = ini.GetInt(#Process.name, 2);
156
			icon_n = ini.GetInt(#Process.name, 2);
157
			if (CheckActiveProcess(Process.ID)) && (Process.status_window!=2) {
157
			if (CheckActiveProcess(Process.ID)) && (Process.status_window!=2) {
158
				current_process_id = Process.ID;
158
				current_process_id = Process.ID;
159
				status_color = COLOR_ACTIVE;
159
				status_color = COLOR_ACTIVE;
160
			} 
160
			} 
161
			else {
161
			else {
162
				status_color = COLOR_OPENED;
162
				status_color = COLOR_OPENED;
163
			}			
163
			}			
164
		} 
164
		} 
165
		DrawWideRectangle(posx, posy, 40, 40, CELL_PADDING, COLOR_BG);
165
		DrawWideRectangle(posx, posy, 40, 40, CELL_PADDING, COLOR_BG);
166
		DefineButton(posx, posy, CELLW-1, CELLH, 100+i+BT_HIDE+BT_NOFRAME, NULL);
166
		DefineButton(posx, posy, CELLW-1, CELLH, 100+i+BT_HIDE+BT_NOFRAME, NULL);
167
		draw_icon_32(posx+CELL_PADDING, posy+CELL_PADDING, COLOR_BG, icon_n);
167
		draw_icon_32(posx+CELL_PADDING, posy+CELL_PADDING, COLOR_BG, icon_n);
168
 
168
 
169
		if (ATTACHEMENT_BOTTOM==attachement) DrawBar(posx, posy+CELLH-ACTIVE_SIZE, CELLW, ACTIVE_SIZE, status_color);
169
		if (ATTACHEMENT_BOTTOM==attachement) DrawBar(posx, posy+CELLH-ACTIVE_SIZE, CELLW, ACTIVE_SIZE, status_color);
170
		if (ATTACHEMENT_LEFT  ==attachement) DrawBar(posx, posy, ACTIVE_SIZE, CELLH, status_color);
170
		if (ATTACHEMENT_LEFT  ==attachement) DrawBar(posx, posy, ACTIVE_SIZE, CELLH, status_color);
171
		if (ATTACHEMENT_TOP   ==attachement) DrawBar(posx, posy, CELLW, ACTIVE_SIZE, status_color);
171
		if (ATTACHEMENT_TOP   ==attachement) DrawBar(posx, posy, CELLW, ACTIVE_SIZE, status_color);
172
		if (ATTACHEMENT_RIGHT ==attachement) DrawBar(posx+CELLW-ACTIVE_SIZE, posy, ACTIVE_SIZE, CELLH, status_color);
172
		if (ATTACHEMENT_RIGHT ==attachement) DrawBar(posx+CELLW-ACTIVE_SIZE, posy, ACTIVE_SIZE, CELLH, status_color);
173
 
173
 
174
		if (ATTACHEMENT_TOP==attachement) || (ATTACHEMENT_BOTTOM==attachement) {
174
		if (ATTACHEMENT_TOP==attachement) || (ATTACHEMENT_BOTTOM==attachement) {
175
			posx += CELLW;
175
			posx += CELLW;
176
			DrawBar(posx, posy, CELL_MARGIN_X, list.h, COLOR_BG);
176
			DrawBar(posx, posy, CELL_MARGIN_X, list.h, COLOR_BG);
177
			posx += CELL_MARGIN_X;
177
			posx += CELL_MARGIN_X;
178
		}
178
		}
179
		if (ATTACHEMENT_LEFT==attachement) || (ATTACHEMENT_RIGHT==attachement) {
179
		if (ATTACHEMENT_LEFT==attachement) || (ATTACHEMENT_RIGHT==attachement) {
180
			posy += CELLH;
180
			posy += CELLH;
181
			DrawBar(posx, posy, list.w, CELL_MARGIN_Y, COLOR_BG);
181
			DrawBar(posx, posy, list.w, CELL_MARGIN_Y, COLOR_BG);
182
			posy += CELL_MARGIN_Y;
182
			posy += CELL_MARGIN_Y;
183
		}
183
		}
184
	}
184
	}
185
	DrawBar(posx, posy, list.w, list.h, COLOR_BG);
185
	DrawBar(posx, posy, list.w, list.h, COLOR_BG);
186
}
186
}
187
 
187
 
188
void SetAttachement()
188
void SetAttachement()
189
{
189
{
190
	if (attachement==ATTACHEMENT_LEFT) {
190
	if (attachement==ATTACHEMENT_LEFT) {
191
		DefineUnDragableWindow(0, 0, CELLW-1, screen.height);
191
		DefineUnDragableWindow(0, 0, CELLW-1, screen.h);
192
		SetClientScreenArea(CELLW, screen.width-CELLW, 0, screen.height);
192
		SetClientScreenArea(CELLW, screen.w-CELLW, 0, screen.h);
193
	}
193
	}
194
	if (attachement==ATTACHEMENT_RIGHT) {
194
	if (attachement==ATTACHEMENT_RIGHT) {
195
		DefineUnDragableWindow(screen.width - CELLW, 0, CELLW, screen.height);
195
		DefineUnDragableWindow(screen.w - CELLW, 0, CELLW, screen.h);
196
		SetClientScreenArea(0, screen.width-CELLW, 0, screen.height);
196
		SetClientScreenArea(0, screen.w-CELLW, 0, screen.h);
197
	}
197
	}
198
	if (attachement==ATTACHEMENT_TOP) {
198
	if (attachement==ATTACHEMENT_TOP) {
199
		DefineUnDragableWindow(0, 0, screen.width, CELLH-1);
199
		DefineUnDragableWindow(0, 0, screen.w, CELLH-1);
200
		SetClientScreenArea(0, 0, CELLH, screen.height);
200
		SetClientScreenArea(0, 0, CELLH, screen.h);
201
	}
201
	}
202
	if (attachement==ATTACHEMENT_BOTTOM) {
202
	if (attachement==ATTACHEMENT_BOTTOM) {
203
		DefineUnDragableWindow(0, screen.height, screen.width, CELLH);
203
		DefineUnDragableWindow(0, screen.h, screen.w, CELLH);
204
		SetClientScreenArea(0, 0, 0, screen.height - CELLH);
204
		SetClientScreenArea(0, 0, 0, screen.h - CELLH);
205
	}
205
	}
206
}
206
}
207
 
207
 
208
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
208
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
209
{
209
{
210
	attached.add(key_name);
210
	attached.add(key_name);
211
	return true;
211
	return true;
212
}
212
}
213
 
213
 
214
void GetAttachedItems()
214
void GetAttachedItems()
215
{
215
{
216
	attached.drop();
216
	attached.drop();
217
	ini_enum_keys stdcall ("/sys/settings/appicons.ini", "attached", #draw_icons_from_section);
217
	ini_enum_keys stdcall ("/sys/settings/appicons.ini", "attached", #draw_icons_from_section);
218
}
218
}
219
//===================================================//
219
//===================================================//
220
//                                                   //
220
//                                                   //
221
//                      EVENTS                       //
221
//                      EVENTS                       //
222
//                                                   //
222
//                                                   //
223
//===================================================//
223
//===================================================//
224
 
224
 
225
//If we clicked on current active process then minimize it
225
//If we clicked on current active process then minimize it
226
//else set active
226
//else set active
227
void EventSetActiveProcess(dword i)
227
void EventSetActiveProcess(dword i)
228
{
228
{
229
	GetProcessInfo(#Process, proc_list[i+list.first]);
229
	GetProcessInfo(#Process, proc_list[i+list.first]);
230
	Process.slot = GetProcessSlot(Process.ID);
230
	Process.slot = GetProcessSlot(Process.ID);
231
	if (Process.ID) ActivateWindow(Process.slot);
231
	if (Process.ID) ActivateWindow(Process.slot);
232
	if (current_process_id == Process.ID) && (Process.status_window!=2) { 
232
	if (current_process_id == Process.ID) && (Process.status_window!=2) { 
233
		MinimizeWindow();
233
		MinimizeWindow();
234
		//TODO: make another window active
234
		//TODO: make another window active
235
	}
235
	}
236
	DrawProcessList();
236
	DrawProcessList();
237
}
237
}
238
 
238
 
239
 
239
 
240
stop:
240
stop: