Subversion Repositories Kolibri OS

Rev

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