Subversion Repositories Kolibri OS

Rev

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