Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

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