Subversion Repositories Kolibri OS

Rev

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

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