Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7614 leency 1
//===================================================//
2
//                                                   //
3
//                       DATA                        //
4
//                                                   //
5
//===================================================//
6
 
7
#define T_WINDOW_TITLE "Process Manager"
8
#define T_SHOW_SYSTEM_PROCESSES "Show system"
9
#define T_DETAILS "Details"
10
#define T_END_PROCESS "End process"
11
 
12
#define BOTPANEL_H 36
13
 
14
enum {
15
	BTN_ID_SHOW_SYSTEM_PROCESSES=200,
16
	BTN_ID_KILL_PROCESS,
17
	BTN_ID_SHOW_PROCESS_INFO
18
};
19
 
20
int current_process_id = 0;
21
unsigned maxcpu;
22
int proc_list[256];
23
 
24
checkbox show_system = { T_SHOW_SYSTEM_PROCESSES, false };
25
 
26
//===================================================//
27
//                                                   //
28
//                       CODE                        //
29
//                                                   //
30
//===================================================//
31
 
32
void Processes__Main()
33
{
34
	int btn;
35
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
36
	maxcpu = GetCpuFrequency();
37
	goto _PROCESS_REDRAW;
38
	loop()
39
	{
40
	  WaitEventTimeout(50);
41
	  switch(EAX & 0xFF)
42
	  {
43
	   	case evMouse:
44
			SelectList_ProcessMouse();
45
			break;
46
		case evKey:
47
			GetKeys();
48
			if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
49
			break;
50
		case evButton:
51
			btn = GetButtonID();
52
			Sysmon__ButtonEvent(btn);
53
 
54
			if (show_system.click(btn))
55
			{
56
				SelectList_LineChanged();
57
			}
58
			if (BTN_ID_KILL_PROCESS == btn)
59
			{
60
				KillProcess(current_process_id);
61
				pause(10);
62
				SelectList_LineChanged();
63
			}
64
			if (BTN_ID_SHOW_PROCESS_INFO == btn)
65
			{
66
				io.run("/sys/tinfo", itoa(GetProcessSlot(current_process_id)));
67
			}
68
			break;
69
		case evReDraw:
70
			_PROCESS_REDRAW:
71
			if (!Sysmon__DefineAndDrawWindow()) break;
72
 
73
			SelectList_Init(WIN_PAD, WIN_CONTENT_Y,
74
				WIN_CONTENT_W-scroll1.size_x,
75
				WIN_CONTENT_H-BOTPANEL_H-TAB_HEIGHT, false);
76
			SelectList_DrawBorder();
77
 
7806 leency 78
			//DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, 4, sc.work);
7614 leency 79
			DrawBar(select_list.x-2, select_list.y+select_list.h+2,
7806 leency 80
				select_list.w+scroll1.size_x+4, BOTPANEL_H, sc.work);
7614 leency 81
			DrawCaptButton(Form.cwidth-110-WIN_PAD,
82
				select_list.y+select_list.h+5,
83
				110,25,BTN_ID_KILL_PROCESS,0xF38181, 0xFFFfff, T_END_PROCESS);
84
			DrawCaptButton(Form.cwidth-230-WIN_PAD,
85
				select_list.y+select_list.h+5,
86
				110,25,BTN_ID_SHOW_PROCESS_INFO,
7806 leency 87
				sc.button, sc.button_text, T_DETAILS);
7614 leency 88
			show_system.draw(select_list.x + 3, select_list.y+select_list.h+10);
89
		default:
90
			SelectList_LineChanged();
91
	  }
92
	}
93
}
94
 
95
void Processes__GetProcessList()
96
{
97
	int i, j;
98
	proc_info Process;
99
 
100
	select_list.count=0;
101
	for (i=0; i
102
	{
103
		GetProcessInfo(#Process, i);
104
		if (Process.name)
105
		{
106
			for (j=0; j<11; j++) if (Process.name[j]!=' ') {
107
				if (show_system.checked==false) {
108
					//do not show system process
109
					if (Process.name[0]=='@') break;
110
					if (!strcmp(#Process.name, "IDLE")) break;
111
					if (!strcmp(#Process.name, "OS")) break;
112
				}
113
				proc_list[select_list.count] = i;
114
				select_list.count++;
115
				break;
116
			}
117
		}
118
	}
119
}
120
 
121
void SelectList_DrawLine(dword i)
122
{
123
	int posy;
124
	char cpu_use[16];
125
	dword bg_color;
126
	proc_info Process;
127
 
128
	GetProcessInfo(#Process, proc_list[i+select_list.first]);
129
 
130
	posy = i *select_list.item_h + select_list.y;
131
	if (i % 2) bg_color = 0xFFFfff; else bg_color = 0xF0F0F0;
132
	if (i+select_list.first == select_list.cur_y) {
133
		current_process_id = Process.ID;
134
		bg_color = 0x67CCEB;
135
	}
136
	DrawBar(select_list.x, posy, select_list.w, select_list.item_h, bg_color);
137
	WriteText(select_list.x+005, posy+select_list.text_y, select_list.font_type, 0, #Process.name);
138
	WriteText(select_list.w/10*5+select_list.x, posy+select_list.text_y, select_list.font_type, 0x444444, ConvertSizeToKb(Process.use_memory));
139
	sprintf(#cpu_use, "%i %%", Process.use_cpu*100/maxcpu);
140
	if (maxcpu) WriteText(select_list.w/10*8+select_list.x - calc(strlen(#cpu_use)-4*8),
141
		posy+select_list.text_y, select_list.font_type, 0x444444, #cpu_use);
142
}
143
 
144
void SelectList_LineChanged()
145
{
146
	Processes__GetProcessList();
147
	SelectList_Draw();
148
}