Subversion Repositories Kolibri OS

Rev

Rev 7244 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7244 Rev 7357
1
#define MEMSIZE 4096*20
1
#define MEMSIZE 4096*20
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/obj/box_lib.h"
11
#include "../lib/obj/box_lib.h"
12
#include "../lib/io.h"
12
#include "../lib/io.h"
13
#include "../lib/patterns/select_list.h"
13
#include "../lib/patterns/select_list.h"
14
#include "../lib/patterns/restart_process.h"
14
#include "../lib/patterns/restart_process.h"
15
 
15
 
16
//===================================================//
16
//===================================================//
17
//                                                   //
17
//                                                   //
18
//                       DATA                        //
18
//                       DATA                        //
19
//                                                   //
19
//                                                   //
20
//===================================================//
20
//===================================================//
21
 
21
 
22
#define T_WINDOW_TITLE "Process Manager"
22
#define T_WINDOW_TITLE "Process Manager"
23
#define T_SHOW_SYSTEM_PROCESSES "Show system"
23
#define T_SHOW_SYSTEM_PROCESSES "Show system"
24
#define T_DETAILS "Details"
24
#define T_DETAILS "Details"
25
#define T_END_PROCESS "End process"
25
#define T_END_PROCESS "End process"
26
 
26
 
27
 
27
 
28
#define BOTPANEL_H 34
28
#define BOTPANEL_H 34
29
proc_info Form;
29
proc_info Form;
30
proc_info Process;
30
proc_info Process;
31
 
31
 
32
enum {
32
enum {
33
	BTN_ID_SHOW_SYSTEM_PROCESSES=20,
33
	BTN_ID_SHOW_SYSTEM_PROCESSES=20,
34
	BTN_ID_KILL_PROCESS,
34
	BTN_ID_KILL_PROCESS,
35
	BTN_ID_SHOW_PROCESS_INFO
35
	BTN_ID_SHOW_PROCESS_INFO
36
};
36
};
37
 
37
 
38
int current_process_id = 0;
38
int current_process_id = 0;
39
unsigned maxcpu;
39
unsigned maxcpu;
40
int proc_list[256];
40
int proc_list[256];
41
 
41
 
42
checkbox show_system = { T_SHOW_SYSTEM_PROCESSES, false };
42
checkbox show_system = { T_SHOW_SYSTEM_PROCESSES, false };
43
 
43
 
44
//===================================================//
44
//===================================================//
45
//                                                   //
45
//                                                   //
46
//                       CODE                        //
46
//                       CODE                        //
47
//                                                   //
47
//                                                   //
48
//===================================================//
48
//===================================================//
49
 
-
 
50
void GetCpuFrequency() {
-
 
51
	EAX = 18;
-
 
52
	EBX = 5;
-
 
53
	$int 0x40
-
 
54
	maxcpu = EAX;
-
 
55
}
-
 
56
 
49
 
57
void main()
50
void main()
58
{
51
{
59
	int btn;
52
	int btn;
60
	load_dll(boxlib, #box_lib_init,0);
53
	load_dll(boxlib, #box_lib_init,0);
61
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
54
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
62
	GetCpuFrequency();
55
	maxcpu = GetCpuFrequency();
63
	loop()
56
	loop()
64
	{
57
	{
65
	  WaitEventTimeout(50);
58
	  WaitEventTimeout(50);
66
	  switch(EAX & 0xFF)
59
	  switch(EAX & 0xFF)
67
	  {
60
	  {
68
	   	case evMouse:
61
	   	case evMouse:
69
			if (!CheckActiveProcess(Form.ID)) break;
62
			if (!CheckActiveProcess(Form.ID)) break;
70
			SelectList_ProcessMouse();
63
			SelectList_ProcessMouse();
71
			break;
64
			break;
72
		case evKey:
65
		case evKey:
73
			GetKeys();
66
			GetKeys();
74
			if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
67
			if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
75
			break;
68
			break;
76
		case evButton:
69
		case evButton:
77
			btn = GetButtonID();
70
			btn = GetButtonID();
78
			if (1 == btn) 
71
			if (1 == btn) 
79
			{
72
			{
80
				ExitProcess();
73
				ExitProcess();
81
			}
74
			}
82
			if (show_system.click(btn))  
75
			if (show_system.click(btn))  
83
			{
76
			{
84
				SelectList_LineChanged();
77
				SelectList_LineChanged();
85
			}
78
			}
86
			if (BTN_ID_KILL_PROCESS == btn)  
79
			if (BTN_ID_KILL_PROCESS == btn)  
87
			{
80
			{
88
				KillProcess(current_process_id);
81
				KillProcess(current_process_id);
89
				pause(10);
82
				pause(10);
90
				SelectList_LineChanged(); 
83
				SelectList_LineChanged(); 
91
			}
84
			}
92
			if (BTN_ID_SHOW_PROCESS_INFO == btn)  
85
			if (BTN_ID_SHOW_PROCESS_INFO == btn)  
93
			{
86
			{
94
				io.run("/sys/tinfo", itoa(GetProcessSlot(current_process_id))); 
87
				io.run("/sys/tinfo", itoa(GetProcessSlot(current_process_id))); 
95
			}
88
			}
96
			break;
89
			break;
97
		case evReDraw:
90
		case evReDraw:
98
			system.color.get();
91
			system.color.get();
99
			DefineAndDrawWindow(screen.width-400/2,screen.height-450/2,400,454,0x73,0,T_WINDOW_TITLE,0);
92
			DefineAndDrawWindow(screen.width-400/2,screen.height-450/2,400,454,0x73,0,T_WINDOW_TITLE,0);
100
			GetProcessInfo(#Form, SelfInfo);
93
			GetProcessInfo(#Form, SelfInfo);
101
			if (Form.status_window>2) break;
94
			if (Form.status_window>2) break;
102
			if (Form.width  < 300) { MoveSize(OLD,OLD,300,OLD); break; }
95
			if (Form.width  < 300) { MoveSize(OLD,OLD,300,OLD); break; }
103
			if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
96
			if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; }
104
			SelectList_Init(6, 6, Form.cwidth-12 - scroll1.size_x, Form.cheight-12-BOTPANEL_H, false);
97
			SelectList_Init(6, 6, Form.cwidth-12 - scroll1.size_x, Form.cheight-12-BOTPANEL_H, false);
105
			SelectList_DrawBorder();
98
			SelectList_DrawBorder();
106
			DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, 4, system.color.work);
99
			DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, 4, system.color.work);
107
			DrawBar(select_list.x-2, select_list.y+select_list.h+2, 
100
			DrawBar(select_list.x-2, select_list.y+select_list.h+2, 
108
				select_list.w+scroll1.size_x+4, BOTPANEL_H, system.color.work);
101
				select_list.w+scroll1.size_x+4, BOTPANEL_H, system.color.work);
109
			DrawCaptButton(Form.cwidth-116,
102
			DrawCaptButton(Form.cwidth-116,
110
				select_list.y+select_list.h+5,
103
				select_list.y+select_list.h+5,
111
				110,25,BTN_ID_KILL_PROCESS,0xF38181, 0xFFFfff, T_END_PROCESS);
104
				110,25,BTN_ID_KILL_PROCESS,0xF38181, 0xFFFfff, T_END_PROCESS);
112
			DrawCaptButton(Form.cwidth-236,
105
			DrawCaptButton(Form.cwidth-236,
113
				select_list.y+select_list.h+5,
106
				select_list.y+select_list.h+5,
114
				110,25,BTN_ID_SHOW_PROCESS_INFO,
107
				110,25,BTN_ID_SHOW_PROCESS_INFO,
115
				system.color.work_button, system.color.work_button_text, T_DETAILS);
108
				system.color.work_button, system.color.work_button_text, T_DETAILS);
116
			show_system.draw(select_list.x + 3, select_list.y+select_list.h+10);
109
			show_system.draw(select_list.x + 3, select_list.y+select_list.h+10);
117
		default:
110
		default:
118
			SelectList_LineChanged();
111
			SelectList_LineChanged();
119
	  }
112
	  }
120
	}
113
	}
121
}
114
}
122
 
115
 
123
void SelectList_LineChanged() 
116
void SelectList_LineChanged() 
124
{
117
{
125
	GetProcessList();
118
	GetProcessList();
126
	SelectList_Draw();
119
	SelectList_Draw();
127
}
120
}
128
 
121
 
129
 
122
 
130
void GetProcessList()
123
void GetProcessList()
131
{
124
{
132
	int i, j;
125
	int i, j;
133
	select_list.count=0;
126
	select_list.count=0;
134
	for (i=0; i
127
	for (i=0; i
135
	{
128
	{
136
		GetProcessInfo(#Process, i);
129
		GetProcessInfo(#Process, i);
137
		if (Process.name) 
130
		if (Process.name) 
138
		{
131
		{
139
			for (j=0; j<11; j++) if (Process.name[j]!=' ') { 
132
			for (j=0; j<11; j++) if (Process.name[j]!=' ') { 
140
				if (show_system.checked==false) {
133
				if (show_system.checked==false) {
141
					//do not show system process
134
					//do not show system process
142
					if (Process.name[0]=='@') break;
135
					if (Process.name[0]=='@') break;
143
					if (!strcmp(#Process.name, "IDLE")) break;
136
					if (!strcmp(#Process.name, "IDLE")) break;
144
					if (!strcmp(#Process.name, "OS")) break;
137
					if (!strcmp(#Process.name, "OS")) break;
145
				}
138
				}
146
				proc_list[select_list.count] = i;
139
				proc_list[select_list.count] = i;
147
				select_list.count++;
140
				select_list.count++;
148
				break; 
141
				break; 
149
			}
142
			}
150
		}
143
		}
151
	}
144
	}
152
}
145
}
153
 
146
 
154
void SelectList_DrawLine(dword i)
147
void SelectList_DrawLine(dword i)
155
{
148
{
156
	int posy;
149
	int posy;
157
	char cpu_use[16];
150
	char cpu_use[16];
158
	dword bg_color;
151
	dword bg_color;
159
	GetProcessInfo(#Process, proc_list[i+select_list.first]);
152
	GetProcessInfo(#Process, proc_list[i+select_list.first]);
160
	
153
	
161
	posy = i *select_list.item_h + select_list.y;
154
	posy = i *select_list.item_h + select_list.y;
162
	if (i % 2) bg_color = 0xFFFfff; else bg_color = 0xF0F0F0;
155
	if (i % 2) bg_color = 0xFFFfff; else bg_color = 0xF0F0F0;
163
	if (i+select_list.first == select_list.cur_y) {
156
	if (i+select_list.first == select_list.cur_y) {
164
		current_process_id = Process.ID; 
157
		current_process_id = Process.ID; 
165
		bg_color = 0x67CCEB;
158
		bg_color = 0x67CCEB;
166
	}
159
	}
167
	DrawBar(select_list.x, posy, select_list.w, select_list.item_h, bg_color);
160
	DrawBar(select_list.x, posy, select_list.w, select_list.item_h, bg_color);
168
	WriteText(select_list.x+005, posy+select_list.text_y, select_list.font_type, 0, #Process.name);
161
	WriteText(select_list.x+005, posy+select_list.text_y, select_list.font_type, 0, #Process.name);
169
	WriteText(select_list.w/10*5+select_list.x, posy+select_list.text_y, select_list.font_type, 0x444444, ConvertSizeToKb(Process.use_memory));
162
	WriteText(select_list.w/10*5+select_list.x, posy+select_list.text_y, select_list.font_type, 0x444444, ConvertSizeToKb(Process.use_memory));
170
	sprintf(#cpu_use, "%i %%", Process.use_cpu*100/maxcpu);
163
	sprintf(#cpu_use, "%i %%", Process.use_cpu*100/maxcpu);
171
	if (maxcpu) WriteText(select_list.w/10*8+select_list.x - calc(strlen(#cpu_use)-4*8), 
164
	if (maxcpu) WriteText(select_list.w/10*8+select_list.x - calc(strlen(#cpu_use)-4*8), 
172
		posy+select_list.text_y, select_list.font_type, 0x444444, #cpu_use);
165
		posy+select_list.text_y, select_list.font_type, 0x444444, #cpu_use);
173
}
166
}
174
 
167
 
175
 
168
 
176
 
169
 
177
 
170
 
178
 
171
 
179
 
172
 
180
stop:
173
stop: