Subversion Repositories Kolibri OS

Rev

Rev 7244 | Rev 7972 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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