Subversion Repositories Kolibri OS

Rev

Rev 7906 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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