Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Linux

เพิ่มประสิทธิภาพ Ubuntu: สลับจาก GNOME ไป i3 Window Manager

นานมากผมใช้ Full Desktop Environments เช่น GNOME บน Ubuntu พวกมันดู Polished ใช้งานง่ายสำหรับ Beginner และทุกอย่างทำงาน Out of the Box แต่ในฐานะคนใช้เวลาส่วนใหญ่ใน Terminal ผมรู้สึกว่ากำลังใช้เวลาย้ายหน้าต่างมากกว่าทำงานจริง นั่นคือเวลาที่ผมสลับไป i3 Window Manager (โปรแกรมควบคุมการจัดวางหน้าต่างบนหน้าจอ) และ Productivity ของผมกระโดดสูง ไม่เคยมองกลับ

ทำไมผมชอบ i3 Window Manager

ต่างจาก Full Desktop Environment i3 แค่ Window Manager ไม่มี Graphical Layer หนัก ไม่มี Background Services ที่ไม่ได้ขอ และไม่มี Visual Clutter แทนได้ Clean Screen, Logical Window Tiling, Full Keyboard Control, และ Plain Text Config File ตัวอย่าง เปิด Terminal 2 ตัว จะ Auto Split Screen จัดหน้าต่างเป็น Smart Non-overlapping Tiles ไม่มีอะไรซ่อนหรือว่างเปล่า

แม้ Desktop Environments เช่น GNOME ดีสำหรับ Ease of Use และ Visual Appeal ผมพบว่าตัวเองอยากได้อะไรที่ทำงานเร็วขึ้นและ Distractions น้อยลง นี่คือเหตุผลหลักที่ผมชอบ i3wm:

ทุกอย่างควบคุมด้วย Keyboard

หากคุ้นเคย Keyboard Shortcuts (โดยเฉพาะถ้าใช้ Vim) i3 รู้สึกเหมือนบ้าน คุณแทบไม่ต้อง Mouse หมายความว่าหลังเรียน Keybindings สามารถ Navigate Desktop, เปิด/ปิด Applications, และจัดการ Windows ได้โดยไม่ต้องปล่อยมือออกจากคีย์บอร์ดเลย

게다가 ทุกอย่าง เช่น Keybindings, Colors, Startup Programs, Status Bar และอื่นๆ กำหนดค่าผ่าน Plain Text Config File ที่อ่านง่ายมาก

สลับ Workspaces เร็ว

i3wm Workspace Management เป็นฟีเจอร์เด่นอีกอย่าง ใช้งานได้ สร้าง Multiple Workspaces (10 โดยค่าเริ่มต้น) สลับระหว่างกันเกือบ Instant ด้วย Key Combination 简单如 Mod + 1, Mod + 2, Mod + 3 ไม่มี Animation Delay, ไม่มี Compositor Induced Lag แค่ Context Switching ทันที

i3wm เบาอย่างยิ่ง

i3wm เบามากและ Consume System Resources น้อย แม้คอมพิวเตอร์สมัยใหม่มี RAM มาก การใช้ Lightweight Window Manager ยังทำความแตกต่างที่สังเกตได้ใน Performance โดยเฉพาะ Hardware เก่าหรือรัน Resource-intensive Applications

ยากให้ตัวเลขแน่ชัด เพราะ Memory Usage ขึ้นกับ Config และ Apps ที่รัน i3 Window Manager เองใช้ Memory น้อยมาก แต่ Typical Minimal Session กับ Xorg และ Basic Utilities ปกติ Consume ประมาณ 100-300 MB RAM ยังน้อยกว่า Modern Desktop Environments มาก ที่ Idle แล้วกินเกิน 1 GB RAM

Tiling ของ i3wm 合理的มาก

แทนที่ Windows จะลอยทับกัน i3wm จัดเรียงเป็น Grid อัตโนมัติ รับรองว่าไม่มี Screen Space 廢棄 ด้วยนี้สามารถมองเห็น Multiple Windows พร้อมเข้าถึงตลอดเวลาโดยไม่ต้อง Resize หรือ Rearrange ด้วยตนเอง

เพิ่มประสิทธิภาพ Ubuntu: สลับจาก GNOME ไป i3 Window Manager

身为平时同时开 Text Editor, Terminal, และ Browser คนนี้ invaluable ไม่ต้อง Alt Tab วงจรผ่าน Stack of Windows แบบตาบอด

หมายเหตุ: แม้ i3wm เป็น Tiling Window Manager มี Tiling Window Managers ดีอื่นๆ มากสำหรับ Linux แต่ละตัวมี Features และ Config Options เฉพาะตัว

การติดตั้งและตั้งค่า i3wm

ติดตั้ง i3wm บน Ubuntu ง่าย เพราะมีใน Official Repositories สำหรับ Distros อื่น ควรหา i3wm ใน Package Manager หรือ Software Center

ก่อนอื่น Update Package Lists:

sudo apt update

จากนั้นติดตั้ง i3:

sudo apt install i3

สามารถค้นหา i3 ใน Software Center ได้

ระหว่างติดตั้ง อาจPrompt ให้เลือก Display Manager หากไม่แน่ใจ คงค่า Default (บ่อยครั้ง GDM สำหรับ Ubuntu-based Systems) ปลอดภัย กระบวนนี้ติดตั้ง i3 พร้อม i3status (สำหรับ Status Bar) และ i3lock (สำหรับ Screen Locking) ให้ Basic Setup ครบ

เพิ่มเติม ติดตั้ง Extended Package ด้วย:

sudo apt install i3-wm i3status i3lock dmenu

หลังติดตั้งเสร็จ Log Out จาก Ubuntu Session บน Login Screen คลิกไอคอน Gear เล็ก (มักอยู่มุมขวาล่าง หรือถัดจาก Password Box) เลือก i3 จาก Desktop Options และ Login ตามปกติ

เพิ่มประสิทธิภาพ Ubuntu: สลับจาก GNOME ไป i3 Window Manager

ครั้งแรก Launch i3 จะถามว่าอยาก Generate Default Config File หรือไม่ ยอมรับ มันจะถามเลือก Mod Key คือ Windows Key หรือ Alt Mod Key คือสิ่งแยก Typing ธรรมดากับ i3 Commands เลือกที่รู้สึก Natural ผมใช้ Windows Key หลีกเลี่ยง Conflict กับ Terminal Shortcuts

การใช้งาน i3wm

ตอน i3wm ติดตั้งและรันแล้ว มาครอบคลุม Basic Tasks ที่ทำได้:

นำทางด้วย Hotkeys

เกือบทุกอย่างใน i3wm จัดการด้วย Hotkeys มี Predefined มาก แตเปลี่ยนและสร้างเองได้ ก่อนทำอะไร ต้องคุ้นเคย Basic Ones ก่อน

อาจทำงานกับ Terminals มาก เปิด Terminal ด้วย Mod Key + Enter หากกด Mod Key + Enter ซ้ำ จะเห็น Default Pattern ที่ i3 ใช้แบ่งหน้าจอ

เพิ่มประสิทธิภาพ Ubuntu: สลับจาก GNOME ไป i3 Window Manager

ไม่ค่อยมีประโยชน์ตอนมีหลายตัว ลอง Re-position ด้วย Default Navigate: Mod + h (ซ้าย), Mod + j (ลง), Mod + k (ขึ้น), Mod + l (ขวา) คุ้นเคย Vim Users แต่เล็กน้อย Off สามารถเปลี่ยนเป็น Actual Vim Bindings ได้

หากอยาก Move Windows ให้เพิ่ม Shift ต่อ Directional Hotkeys Window จะ Move ทิศทางนั้น Mod + Shift + j (Move ลง)

เปิด Windows ใหม่ Split ตามต้องการ Target Window ที่อยาก Split ใช้ Mod + h (Split Horizontal) และ Mod + v (Split Vertical) ปิด Window: Mod + Shift + q

จัดการ Windows ของ i3wm

i3wm อนุญาต Floating Windows บาง Windows เช่น GIMP Toolbars จะเปิด Floating อัตโนมัติ แต่ทำให้ Window ใดๆ Float ได้ Mod + Shift + Space สลับระหว่าง Floating และ Tiled Mode สำหรับ Window ที่เลือก

เพิ่มประสิทธิภาพ Ubuntu: สลับจาก GNOME ไป i3 Window Manager

บังคับ Window ไป Full Screen: Mod + f กดอีกครั้งคืนมา

เปิดโปรแกรมใน i3wm

ใช้ Launcher เปิดโปรแกรมใน i3wm Default Launcher คือ dmenu แตแทนที่ได้ด้วย rofi

เพิ่มประสิทธิภาพ Ubuntu: สลับจาก GNOME ไป i3 Window Manager

Launchers เหมือน Search สำหรับ Programs พิมพ์โปรแกรมที่ต้องการ กด Enter โปรแกรมจะ Launch Launcher จะ Track Most Commonly Used Programs แสดงใน List ตอนเปิด Select ได้โดยไม่ต้องพิมพ์

Launcher Hotkey: Mod + d

Basic Configuration ของ i3wm

มี Configuration จำนวนมหาศาลกับ i3wm ครอบคลุมแค่ Basics นี่คือบางอย่างที่มักอยากทำ

หลังสร้าง Default Config ครั้งแรก ระบบวางใน "~/.config/i3/"

mkdir -p ~/.config/i3
cp /etc/i3/config ~/.config/i3/config

เปลี่ยนสีง่าย i3wm ใช้ Hex Values สำหรับ Colors เหมือน CSS มี Classes หลายตัว แต่ละตัวมี Border, Background, Text, และ Indicator Value วางในตารางและใส่ค่าสีที่ต้องการ

class border backgr. text indicator client.focused #1e1e1e #1e1e1e #151515 #AA0000 client.focused_inactive client.unfocused client.urgent client.placeholder client.background #454545

ใน i3wm Config bindsym สร้าง Hotkey ใหม่ exec Launch Programs รวมกันสร้าง Hotkeys เปิดโปรแกรมที่ใช้บ่อยโดยไม่ใช้ Launcher เช่น:

bindsym $mod+Shift+w exec firefox

รัน Applications ตอน Startup ได้ด้วย แค่ใช้ exec สำหรับนั้น

exec firefox

ปรับแต่ง Status Bar

Status Bar เป็นส่วนสำคัญที่สุดของ Desktop แสดง Workspaces และ Vital Information มากมาย กับ i3wm มี Options เยอะสำหรับ Status Bar

ใกล้ท้าย Config File จะเจอ Block ชื่อ bar ทุกอย่างสำห Status Bar จะอยู่ที่นี่

ก่อนอื่นเจอ status_command ให้เลือก Status Bar ที่ใช้ Default คือ i3status แตใช้ตัวอื่นได้มาก เช่น i3blocks, lemonbar, polybar ทุกตัวต่างกัน มี Pros/Cons ของตัวเอง

เปลี่ยนตำแหน่ง Bar ได้ที่นี่:

position top

สร้าง Colors Block แยกได้ที่นี่ ใช้เหมือน Color Config อื่นๆ ปรับ Color Scheme ของ i3

colors { #class #border #bg #txt focused_workspace #454565 #252525 #1E1E1E active_workspace inactive_workspace urgent_workspace binding_mode background #151515 }

i3 เหมาะกับคุณไหม?

i3 อันทรงพลัง แต่ไม่ Perfect หากคุ้นเคย Traditional Point-and-Click Desktop Environments ประสบการณ์อาจรู้สึก Overwhelming ตอนแรก ไม่มี Graphical Settings Panel และ Config ส่วนใหญ่ทำ Manual ผ่าน Plain Text File i3 ไม่รวม Features ที่ User หลายคนคาดหวัง เช่น Desktop Icons, Drag-and-drop Window Placement, หรือ Built-in Graphical Settings Manager สำหรับ User ที่พึ่ง Visual Organization แนวทาง Minimalist นี้อาจรู้สึก Restrictive

ข้อจำกัดสำคัญอีกอย่าง: i3 ทำงานกับ X11 เท่านั้น ไม่ Support Wayland

สำหรับ Gamers i3 ใช้ได้ แต่อาจต้อง Setup เพิ่มเติม เช่น Fullscreen Games รันได้ปกติภายใต้ X11 แต i3 ขาด Built-in Compositor อาจนำไปสู่ Screen Tearing เว้นแต่ Config Compositor เอง ดังนั้น หาก Prioritize Gaming อาจพบ Full Desktop Environment ที่มี Built-in Display Management และ Wayland Support สะดวกกว่าในระยะยาว